So I am trying to pass some props from my top level component to a child component, I have done some searching online but cannot find anything that shows how I can pass this.props.children WITH some values my component's state. Here is my code.
Layout (Parent):
export default class Layout extends React.Component {
constructor (props) {
super(props)
this.state = { data: 'test' }
}
render() {
const {location} = this.props;
console.log("layout");
return (
<div>
<Nav location={location}/>
<div className="container">
<div className="row">
<div className="col-lg-12">
{this.props.children}, data={this.state.data}
</div>
</div>
<Footer/>
</div>
</div>
);
}
}
When I call the "data" props in my next Component:
Home (Child):
//ON COMPONENT RENDER
componentDidMount = () => {
console.log("home");
console.log(this.props.data);
}
In my console it returns:
home
Undefined
Any pointers to how I should be doping this? Any help is appreciated, thank you in advance.