Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //...other imports...
- import React, {Component} from 'react'
- import MyUserComponent from './MyUserComponent'
- import appState from './appState'
- // setup initial app state as object
- const initAppState = {
- loading: false,
- userObject: {},
- moreStuff: []
- }
- // call appState with initial state object to get state manager
- const stateManager = appState(initAppState)
- class AppContainer extends Component {
- constructor(props) {
- super(props)
- // set the stateManager's emitter callback so container state gets updates
- stateManager.emitter.callback = x => this.setState(x)
- // load initial container state from the stateManager
- this.state = stateManager.state
- }
- render() {
- const {emitter} = stateManager
- const {userObject} = this.state
- // pass the emitter down to any component that needs
- // to communicate a state change request via
- // props.emitter.emit('update', {...newState})
- return (
- <div>
- <MyUserComponent {emitter} {userObject}/>
- </div>
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement