Last active
August 26, 2016 15:49
-
-
Save peterpme/e8729252d915374f26ddeac08913e6a5 to your computer and use it in GitHub Desktop.
How can I pass both the key and the value without resorting to bind?
This file contains hidden or 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
const handleFieldUpdate = (key) => (value) => setState({ [key]: value }) | |
const SomeForm = () => ( | |
<Input | |
placeholder='Name' | |
onChange={handleFieldUpdate('name')} | |
/> | |
) | |
const Input = ({ | |
value, | |
placeholder, | |
onChange, | |
}) => ( | |
<TextInput // React Native | |
value={value} | |
placeholder={placeholder} | |
onChangeText={onChange} | |
/> | |
) |
This file contains hidden or 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
function handleFieldUpdate(key, value) { | |
this.setState({ | |
[key]: value, | |
}); | |
} | |
const SomeForm = () => ( | |
<Input | |
placeholder='Name' | |
onChange={handleFieldUpdate} | |
/> | |
) | |
const Input = ({ | |
value, | |
placeholder, | |
onChange, | |
}) => ( | |
<TextInput // React Native | |
value={value} | |
placeholder={placeholder} | |
onChangeText={onChange} | |
/> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment