Skip to content

Instantly share code, notes, and snippets.

@mDibyo
Created December 27, 2018 08:54
Show Gist options
  • Save mDibyo/c1b16ccf2b965a2cd245c351af8ca630 to your computer and use it in GitHub Desktop.
Save mDibyo/c1b16ccf2b965a2cd245c351af8ca630 to your computer and use it in GitHub Desktop.
import withHooksSupport from 'with-hooks-support';
class Input extends React.PureComponent {
render() {
const { value, onChange } = useFormInput('Take 2!');
return <input value={value} onChange={onChange} />;
}
}
export default withHooksSupport(Input);
function useFormInput(initialValue) {
const [value, setValue] = useState(initialValue);
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