-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useState } from 'react'; | ||
|
||
/** | ||
* | ||
* Custom hook to create controlled form component. | ||
* | ||
* @param {Object} initialState State object with name of each form input as keys and | ||
* corresponding initial state as values. | ||
* @return {Array} Array containing values and onChange function respectively. | ||
*/ | ||
const useForm = (initialValues) => { | ||
const [values, setValues] = useState(initialValues); | ||
|
||
const onChange = (event) => { | ||
setValues((previousValues) => ({ ...previousValues, [event.target.name]: event.target.value })); | ||
}; | ||
|
||
return [values, onChange]; | ||
}; | ||
|
||
export default useForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
export { default as useForm } from './hooks/useForm'; | ||
export { default as useState } from './hooks/useStack'; | ||
export { default as useQueue } from './hooks/useQueue'; | ||
export { default as useToggle } from './hooks/useToggle'; | ||
export { default as useDarkMode } from './hooks/useDarkMode'; | ||
export { default as usePrevious } from './hooks/usePrevious'; | ||
export { default as useDebounce } from './hooks/useDebounce'; | ||
export { default as useGeoLocation } from './hooks/useGeoLocation'; | ||
export { default as useLocalStorage } from './hooks/useLocalStorage'; | ||
export { default as useMousePosition } from './hooks/useMousePosition'; | ||
export { default as usePrevious } from './hooks/usePrevious'; | ||
export { default as useQueue } from './hooks/useQueue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters