Skip to content

Instantly share code, notes, and snippets.

View ejoo's full-sized avatar
💭
Programming is an art

Ejaz Karim ejoo

💭
Programming is an art
  • uConnect
  • 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 });