Skip to content

Instantly share code, notes, and snippets.

View Noor-Khan's full-sized avatar
🎯
Focusing

NK Noor-Khan

🎯
Focusing
  • Self Employed
  • Islamabad, Pakistan
View GitHub Profile
@ejoo
ejoo / FormHook.ts
Last active April 15, 2019 07:12
React Form Custom Hook
function useForm(initial, schema) {
const [values, setState] = React.useState(initial);
const [touched, setTouched] = React.useState([]);
const [errors, setErrors] = React.useState(null);
// update field value on change on any input in the form
const onFormChange = e => {
const { name, value } = e.target;
setState({ ...values, [name]: value });