1import React, {Component} from 'react';
2import './App.css';
3import IconBar from './components/icon-bar';
4import Events from './components/events';
5
6class App() extends Component {
7 constructor(props) {
8 super(props)
9 this.state = {
10 mode: null
11 }
12 this.updateMode = this.updateMode.bind(this);
13 }
14
15 updateMode = (newMode) => {
16
17 this.setState({mode: newMode});
18 }
19
20
21 return (
22 <div className="App">
23 <h1 className="Title">ENAKS</h1>
24 <IconBar onUpdateMode={this.updateMode} mode={this.state.mode} />
25 <Events />
26 <div className="mainModeFrame"><p1>{this.state.mode}</p1></div>
27 </div>
28 );
29}
30
31export default App;
32Add this to your knowledge
1If two components need access to the same state
2they should have a common ancestor where the state is kept.