Answers for "react call component state"

0

class component react using state

import React, {Component} from 'react';
import './App.css';
import IconBar from './components/icon-bar';
import Events from './components/events';

class App() extends Component {
  constructor(props) {
        super(props)
        this.state = {
            mode: null
        }
        this.updateMode = this.updateMode.bind(this);
    }

  updateMode = (newMode) => {

      this.setState({mode: newMode});
  }


  return (
    <div className="App">
      <h1 className="Title">ENAKS</h1>
      <IconBar onUpdateMode={this.updateMode}  mode={this.state.mode} />
      <Events />
  <div className="mainModeFrame"><p1>{this.state.mode}</p1></div>
    </div>
  );
}

export default App;
Add this to your knowledge
Posted by: Guest on August-29-2021
0

react call component state

If two components need access to the same state
they should have a common ancestor where the state is kept.
Posted by: Guest on September-21-2021

Code answers related to "react call component state"

Code answers related to "Javascript"

Browse Popular Code Answers by Language