Created
February 25, 2019 14:28
-
-
Save niinpatel/4fac8b6633a126172d8e3a4904fa2a8f 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 React, { useState } from 'react'; | |
const useTextField = name => { | |
const [value, setValue] = useState(''); | |
const onChange = event => { | |
setValue(event.target.value); | |
}; | |
return { | |
name, | |
value, | |
onChange, | |
placeholder: name, | |
}; | |
}; | |
const InputDemoWithHooks = () => { | |
const nameField = useTextField('name'); | |
return <input type="text" {...nameField} />; | |
}; | |
export default InputDemoWithHooks; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As your hook is
useTextField
I would expect it to returntype: "text"
as well :)