Axios calls in actions Redux

Viewed 1923

I am very new to Redux so please bear with me now. My friend suggested that instead of having my axios calls inside of my componentDidMount() I should place them in an action file. Here's the snippet:

  componentDidMount() {
    axios.get('http://xxxx/customers').then(res => {
      this.setState({
        res,
        customer: res.data
      })
    })

    axios.get('http://xxxx/events').then(res => {
      this.setState({
        res,
        event: res.data
      })
    })

    axios.get('http://xxxx/locks').then(res => {
      this.setState({
        res,
        lock: res.data
      })
    })
  }

And I understand that to change the application's state I need to dispatch and action: enter image description here

But the thing is that I am really uncertain how to set this all up. If anyone has some tips I'll be really happy to take them.

4 Answers

There is another library like Redux, the Dynadux.

You can create more sophisticated stores and simply in the componentDidMount you can call store.fetchEntities() without need the await.

Related