File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33## 📗 Index
44
55- [ useLocalStorage] ( #-uselocalstorage )
6+ - [ useForm] ( #-useform )
67- [ useStack] ( #-usestack )
78- [ useQueue] ( #-usequeue )
89- [ useDebounce] ( #-usedebounce )
@@ -51,6 +52,42 @@ const LocalValue = () => {
5152
5253</br >
5354
55+ ## 📃 useForm
56+
57+ Custom hook to create controlled form component.
58+
59+ ### Usage
60+
61+ ``` jsx
62+ import React from " react" ;
63+ import { useForm } from " use-custom-hooks" ;
64+
65+ const Form = () => {
66+ const [values , onChange ] = useLocalStorage ({name: " " ,age: 12 });
67+
68+ return (
69+ < form>
70+ < input type= " text" name= " name" value= {values .name } onChange= {onChange}/ >
71+ < input type= " number" name= " age" value= {values .age } onChange= {onChange}/ >
72+ < / form>
73+ );
74+ };
75+ ```
76+
77+ ### Parameters
78+
79+ 1 . ` initialValue ` (_ Object_ ) : State object with name of each form input as keys and corresponding initial state as values.
80+
81+ ### Return value
82+
83+ ` [values,onChange] `
84+
85+ 1 . ` values ` (_ Object_ ) : Values of input components.
86+ 2 . ` onChange ` (_ function_ ) : Function to be added to onChange event of input component.
87+
88+ </br >
89+
90+
5491## 📚 useStack
5592Hook for creating and managing Stack.
5693
Original file line number Diff line number Diff line change 1+ import { useState } from 'react' ;
2+
3+ /**
4+ *
5+ * Custom hook to create controlled form component.
6+ *
7+ * @param {Object } initialState State object with name of each form input as keys and
8+ * corresponding initial state as values.
9+ * @return {Array } Array containing values and onChange function respectively.
10+ */
11+ const useForm = ( initialValues ) => {
12+ const [ values , setValues ] = useState ( initialValues ) ;
13+
14+ const onChange = ( event ) => {
15+ setValues ( ( previousValues ) => ( { ...previousValues , [ event . target . name ] : event . target . value } ) ) ;
16+ } ;
17+
18+ return [ values , onChange ] ;
19+ } ;
20+
21+ export default useForm ;
Original file line number Diff line number Diff line change 1+ export { default as useForm } from './hooks/useForm' ;
12export { default as useState } from './hooks/useStack' ;
3+ export { default as useQueue } from './hooks/useQueue' ;
24export { default as useToggle } from './hooks/useToggle' ;
35export { default as useDarkMode } from './hooks/useDarkMode' ;
6+ export { default as usePrevious } from './hooks/usePrevious' ;
47export { default as useDebounce } from './hooks/useDebounce' ;
58export { default as useGeoLocation } from './hooks/useGeoLocation' ;
69export { default as useLocalStorage } from './hooks/useLocalStorage' ;
710export { default as useMousePosition } from './hooks/useMousePosition' ;
8- export { default as usePrevious } from './hooks/usePrevious' ;
9- export { default as useQueue } from './hooks/useQueue' ;
Original file line number Diff line number Diff line change 11{
22 "name" : " use-custom-hooks" ,
3- "version" : " 1.7 .0" ,
3+ "version" : " 1.8 .0" ,
44 "description" : " A collection of Custom Hooks for React." ,
55 "main" : " index.js" ,
66 "scripts" : {
You can’t perform that action at this time.
0 commit comments