Say I have a class component called 'Parent' which renders a component called 'Child':
class Parent extends React.Component {
constructor(props) {
super(props);
this.state = {
someProperty = 'some value',
};
}
setProperty: newValue => {
this.setState({someProperty: newValue});
}
render() {
return < Child setProperty: {this.setProperty} />
}
and the Child component:
const Child = props => {
return <button onClick={props.setProperty('new value')} />
}
So this works, and it makes sense to me: We're passing a reference to setProperty, which is then whenever a child component is clicked.
In many tutorials, I see the following code (in Parent):
render() {
return < Child setProperty: {newValue => this.setProperty(newValue) />
}
Is there a benefit to doing this when passing a function along?