Reactjs: Passing Props From Card Component To Tab Component
i am new to react. I am trying to pass the props from the child component to the parent component tabs which has favourites tabs. so i thought I will pass the values from handleCl
Solution 1:
Example:
You have structure:
<Parent>
<Tabs />
<Child />
</Parent>
Then your Parent component should be as below. You pass new added favorites as props downward to Tabs. You add new favorites updating the parent state.
class Parent extends Component {
constructor(props) {
super(props);
this.state = {
favorites: []
}
this.handleClick = this.handleClick.bind(this);
}
// props
handleClick(prop) {
this.setState({ favorites: this.state.concat(prop) })
}
render() {
const { favorites } = this.state;
return (
<div>
<Tabs favorites={ favorites } />
<Child onClick={ this.handleClick }/>
</div>
)
}
}
Post a Comment for "Reactjs: Passing Props From Card Component To Tab Component"