Skip to content

bkinno/react-state-util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-state-util

Add global state to React (like root style in AngularJS but keep the React philosophie)

ConnectGlobalState

Usage

  • Connect Component to state global
  class App extends Component {
      render() {
          return (
              <div>
                  <h3>App Component</h3>
                  <button onClick={ ()=>this.setGlobalState({name:'Huan Nguyen'}) }>Change Name</button>
                  <div>Hello {this.globalState.name || 'Phong' }</div>
              </div>
          );
      }
  }

  export default connectGlobalState(App);
  • Set state global this.setGlobalState({ [stateName]:[stateValue] })
 this.setGlobalState({name:'Bob'})
  • Get state global this.globalState.[stateName]
this.globalState.name //Bob

About

Add global state to React (like root style in AngularJS but keep the React philosophie)

Resources

License

Stars

Watchers

Forks

Packages

No packages published