Answer the question
In order to leave comments, you need to log in
How to update react child component from child component?
Hello, I have 3 components, the main App.js, where there is state and route:
class App extends React.Component {
constructor(){
super();
this.state = {
logged: false
}
}
async LogOrLogout(loggin){
await this.setState({logged: loggin});
console.log(this.state);
}
render(){
return (
<BrowserRouter>
<div className="app">
{(this.state.logged) ? <HeaderComponent logged={true}/> : <HeaderComponent logged={false}/>}
<Route exact path='/' component={MainPageUnLogComponent}/>
<Route path='/main-menu' component={MainPageLogComponent}/>
<Route path='/login' component={() => <LoginComponent login={loggin => this.LogOrLogout(loggin)}/>}/>
<Route path='/registration' component={RegisterComponent}/>
</div>
</BrowserRouter>
);
}
}
Answer the question
In order to leave comments, you need to log in
header does not change, I figured out the reason, because it was drawn at the beginning and was not drawn anymorein fact, it should change, this is the essence of react, replace
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question