Skip to content

Instantly share code, notes, and snippets.

@kocisov
Created August 3, 2017 20:21
Show Gist options
  • Save kocisov/4520b9545cd9f5f198d02137d3ac34fe to your computer and use it in GitHub Desktop.
Save kocisov/4520b9545cd9f5f198d02137d3ac34fe to your computer and use it in GitHub Desktop.
tp02l
// example
// don't overthink this too much
class X extends PureComponent {
// constructor equivalent for creating initial state
state = {
something: ''
}
// function that returns another function
changeReturn = () => e => {
this.setState({
[e.target.name]: e.target.value
})
}
// function that sets controlled input value
change = e => {
this.setState({
[e.target.name]: e.target.value
})
}
// render
render() {
return (
<div>
Immediately called
<input type="text" name="something" placeholder="Write something..." onChange={this.changeReturn()}>
Not immediately called
<input type="text" name="something" placeholder="Write something..." onChange={this.change}>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment