How do I get a state from a child component?
In my example I have Shell.js which is the parent component:
class Shell extends Component {
render() {
return (
<div>
<Nav propsdaNav={1} />
<SupermarketDetail />
</div>
);
}
}
export default Shell;
I want to get the state
of the <SupermarketDetail />
component and apply the return as props
on the <Nav />
component instead of the number 1.
SupermarketDetail.js looks like this:
class SupermarketDetail extends Component {
constructor(props) {
super(props);
this.state = {
detailState: 0
}
}
handleState(number) {
this.setState({ detailState: number });
}
componentDidMount() {
this.handleState(1)
}
componentWillUnmount() {
this.handleState(0)
}
render() {
return (
<div className="containerDetail">
....
</div>
);
}
}
export default SupermarketDetail;
I would like to receive this detailState
in the parent component. Any ideas?