Answer the question
In order to leave comments, you need to log in
Is it possible to somehow pass the name of the state element from the child to the parent in Raect?
Is it possible to somehow pass the name of the state element from the child to the parent in Raect?
Parent:
class Container extends Component {
constructor() {
super();
this.state = {
test: 1
};
this.buyEgg = this.buyEgg.bind(this);
}
buyEgg(value) {
this.setState({ value: 2 });
}
render() {
return (
<div>
<TestShop buyEgg={this.buyEgg} test={this.state.test} />
</div>
);
}
class TestShop extends Component {
constructor(props) {
super();
this.state = {
};
}
render() {
return (
<div>
<h1>{this.props.test}</h1>
<button value="test" onClick={() => this.props.buyEgg('test')}>
Click
</button>
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question