Created
December 27, 2018 08:54
-
-
Save mDibyo/c1b16ccf2b965a2cd245c351af8ca630 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 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