Skip to content

Instantly share code, notes, and snippets.

@kidqueb
Created January 27, 2020 20:54
Show Gist options
  • Save kidqueb/ce87f7547c2482020e65ceece510486a to your computer and use it in GitHub Desktop.
Save kidqueb/ce87f7547c2482020e65ceece510486a to your computer and use it in GitHub Desktop.
Simple form management hook
import { useState } from "preact/hooks";
export function useInputHandler(defaultState) {
const [state, setState] = useState(defaultState);
return [
state,
event => setState({ ...state, [event.target.name]: event.target.value }),
newState => setState({ ...state, ...newState })
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment