Last active
December 22, 2018 08:40
-
-
Save mDibyo/f4f5b512cf1d3698bd7b7f9b671884f9 to your computer and use it in GitHub Desktop.
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 withHook from 'with-hook'; | |
class HookedInput extends React.PureComponent { | |
render() { | |
const WithFormInputProps = withHook(useFormInput); | |
return ( | |
<WithFormInputProps> | |
{({ value, onChange }) => <input value={value} onChange={onChange} />} | |
</WithFormInputProps> | |
); | |
} | |
} | |
function useFormInput() { | |
const [value, setValue] = useState(""); | |
const handleInputChange = e => setValue(e.target.value); | |
return { value, onChange: handleInputChange }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment