Created
March 20, 2020 20:08
-
-
Save NavizDev/cb3ba62cedd01bc78052203b1b84d6fb to your computer and use it in GitHub Desktop.
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
import { useState, useEffect } from "react"; | |
const useForm = ({ initialValues }) => { | |
console.log(initialValues); | |
const [fields, setFields] = useState(initialValues); | |
const onChange = event => { | |
const { value, name } = event.target; | |
setFields({ ...fields, [name]: value }); | |
}; | |
useEffect(() => { | |
setFields(initialValues); | |
}); | |
return { | |
fields, | |
getInput: name => ({ | |
name, | |
value: fields[name], | |
onChange | |
}), | |
getSelect: name => ({ | |
name, | |
value: fields[name], | |
onChange | |
}) | |
}; | |
}; | |
export default useForm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment