AppComponent

AppComponent is a replacement for React.Component for any component that needs access to appState. Any AppComponent must be a descendent of a RootAppComponent (that is, all AppComponents must have a RootAppComponent above them, but not necessarily directly above them, in their component tree).

Usage

AppComponent is a base component, so you should extend from it like you would React.Component.

class SomeComponent extends AppComponent {
  // ...
}

Your component can access this.appState in render(), as you would access this.state, and can call this.setAppState from within any event handlers, as you would for this.setState.

class SomeComponent extends AppComponent {

  render() {
    return (
      <input
        type="button"
        value={"clicked " + this.appState.buttonClickedCount + " times"}
        onClick={() => this.setAppState({
          buttonClickedCount: this.appState.buttonClickedCount + 1,
        })}
      />
    );
  }
}

API

this.appState

Access appState. this.appState should be initialized in your root component's constructor (or via appState = inside the class body).

this.setAppState(update, callback)

this.appStateContext

shouldComponentUpdate(nextProps, nextState, nextAppState)

componentDidUpdate(prevProps, prevState, snapshot, prevAppState)

And all React.Component methods

results matching ""

    No results matching ""