Я пытаюсь передать реквизиты от родительского компонента к дочернему компоненту, и хотя его вызывают дважды (не знаю, почему componentDidMount
нужно вызывать только один раз), реквизиты кажутся пустыми.
Родительский компонент:
class Members extends Component{
constructor(props){
super(props);
this.state = {
interests: []
}
}
componentDidMount(){
fetch(interestUrl, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"Authorization": this.props.authToken
}
})
.then((response) => response.json())
.then((json) => {this.setState({interests: json})})
.catch(error => {console.log("Error: " + error)})
};
render(){
return(
<div className="Members-body">
<div className="Menu-sidebar">
<Menu interestList = {this.state.interests}/>
</div>
<div className="Main-container">
<Main/>
</div>
</div>
)
}
}
export default Members;
Дочерний компонент:
class Menu extends Component {
constructor(props){
super(props);
}
componentDidMount(){
console.log("interestList: " + this.props.interestList);
}
render() {
return(
<div className="Menu-container">
este es el menu de la aplicacion
</div>
)
}
}
export default Menu;
Журнал консоли от componentDidMount внутри компонента Menu печатает:
interestList:
interestList:
Есть идеи, чтобы указать мне правильное направление?
С благодарностью!