Created
January 27, 2020 20:54
-
-
Save kidqueb/ce87f7547c2482020e65ceece510486a to your computer and use it in GitHub Desktop.
Simple form management hook
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 } 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