Skip to content

Instantly share code, notes, and snippets.

@markodayan
Last active March 5, 2020 21:59
Show Gist options
  • Save markodayan/43a7e7c95b1e234d968b9f3fce2b37b6 to your computer and use it in GitHub Desktop.
Save markodayan/43a7e7c95b1e234d968b9f3fce2b37b6 to your computer and use it in GitHub Desktop.
Custom Hooks in React (Form Input State Management)
import { useState } from 'react';
export const useForm = initialValues => {
const [values, setValues] = useState(initialValues);
return [
values,
e => {
setValues({
...values,
[e.target.name]: e.target.value
});
}
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment