Skip to content

Instantly share code, notes, and snippets.

@mDibyo
Last active December 22, 2018 08:40
Show Gist options
  • Save mDibyo/f4f5b512cf1d3698bd7b7f9b671884f9 to your computer and use it in GitHub Desktop.
Save mDibyo/f4f5b512cf1d3698bd7b7f9b671884f9 to your computer and use it in GitHub Desktop.
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