0

I want to populate two tokens properties via AJAX whenever the state is created. It seems that Redux doesn't have much documentation on this. I can't use componentWillMount to do this because the way I have my containers set up it just won't work.

const Auth = Record({
  token: '',
  yelpToken: '',
});

Is there someway run a function that will happen before createStore is invoked?

Chris Pena
  • 374
  • 1
  • 4
  • 10
  • you want to make an ajax call when the store is created and populate the two fields before you render? is this in a server side render context or on the client? – Alex Moldovan Jan 22 '17 at 08:39

1 Answers1

1

You can replace your index with this:

 class EntryPoint extends Components {
        constructor(){
            this.state = {
                //can be replaced with store state..
                finishedFetching: false
            }
        }
        componentDidMount() {
            //you can chain dispatches with redux thunk
            dispatch(fetchAsyncData())
                .then(() => this.setState({finishedFetching: true}))
        }
        render() {
            return this.state.finishedFetching ? <App/> : null;
        }
}
nirsky
  • 2,955
  • 3
  • 22
  • 35