Skip to content

Commit d6d4e81

Browse files
committed
hooks
1 parent 80d0ae0 commit d6d4e81

File tree

5 files changed

+21
-31
lines changed

5 files changed

+21
-31
lines changed

client/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ModalCardEdit from './Cards/ModalCardEdit'
99
import ModalLogin from './Login/ModalLogin'
1010
import DataService from './Services/DataService'
1111
import Card, { checkCardsArr } from './Cards/cardType/Card'
12-
import useDebouncedEffect from './Shared/useDebouncedEffect'
12+
import useDebouncedEffect from './Shared/useDebouncedEffect.hook'
1313

1414
const { loadData, postData, updDataServLogin } = DataService()
1515

client/src/Cards/AddCard.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
import React, { useState } from 'react'
1+
import React from 'react'
22
import PropTypes from 'prop-types'
33
import TextareaAutosize from 'react-textarea-autosize'
44
import Palette, { colors } from './palette/palette'
5-
6-
function useInputValue(defaultValue) {
7-
const [value, setValue] = useState(defaultValue)
8-
return {
9-
bind: {
10-
value,
11-
onChange: event => setValue(event.target.value)
12-
},
13-
clear: () => setValue(defaultValue),
14-
value: () => value,
15-
addBreak: () => setValue(value + "\n")
16-
}
17-
}
5+
import useInputValue from '../Shared/useInputValue.hook'
186

197
function AddCard({ onCreate, onDeleteAll }) {
208
const input = useInputValue('')
@@ -36,8 +24,8 @@ function AddCard({ onCreate, onDeleteAll }) {
3624
}
3725

3826
function submitHandler() {
39-
if (String(input.value()).trim() && String(color).trim()) {
40-
onCreate({ name: String(input.value()).trim(), text: "", color: String(color) })
27+
if (String(input.value).trim() && String(color).trim()) {
28+
onCreate({ name: String(input.value).trim(), text: "", color: String(color) })
4129
input.clear()
4230
setColor(defColor)
4331
}
@@ -71,7 +59,7 @@ function AddCard({ onCreate, onDeleteAll }) {
7159
</div>
7260

7361
<div className="col-xl-1 col-lg-1 col-md-1 col p-1">
74-
<button disabled={!input.value().trim()} className="btn btn-success btn-block" onClick={submitHandler}>
62+
<button disabled={!input.value.trim()} className="btn btn-success btn-block" onClick={submitHandler}>
7563
<i className="bi bi-clipboard-plus"></i>
7664
</button>
7765
</div>

client/src/Login/ModalLogin.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react"
22
import Modal, { ModalProps } from "../Shared/Modal/Modal"
33
import PropTypes from 'prop-types'
4+
import useInputValue from '../Shared/useInputValue.hook'
45
import LoginService from '../Services/LoginService'
56
const { logIn, logOut } = LoginService()
67

@@ -12,19 +13,6 @@ function validateUsername(str) {
1213
return String(str).replace(/@|;|:|\.|,|\/|\\|\||\$|\?|!|#|%|\*|\^|\+|=|\[|\]| |\\ |«|<|>/gi, "").trim()
1314
}
1415

15-
function useInputValue(defaultValue) {
16-
const [value, setValue] = React.useState(defaultValue)
17-
18-
return {
19-
bind: {
20-
value: value,
21-
onChange: event => setValue(event.target.value)
22-
},
23-
clear: () => setValue(""),
24-
value: value
25-
}
26-
}
27-
2816
function ModalLogin(props) {
2917
const { onLogin, onLogout, logged, userName, isOpen, setOpenState } = props
3018

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { useState } from 'react'
2+
3+
export default function useInputValue(defaultValue) {
4+
const [value, setValue] = useState(defaultValue)
5+
return {
6+
bind: {
7+
value,
8+
onChange: event => setValue(event.target.value)
9+
},
10+
clear: () => setValue(defaultValue),
11+
value: value,
12+
addBreak: () => setValue(value + "\n")
13+
}
14+
}

0 commit comments

Comments
 (0)