P
P
Praud2017-05-23 21:56:52
JavaScript
Praud, 2017-05-23 21:56:52

How to properly handle Promise redux?

Hello. How to properly handle an asynchronous promise ?

export default connect(
  null,
  dispatch => ({
      onLoginSystem: (account) => {
        return dispatch(loginSystem(account));
      }
  })
)(AdminPanel);

import axios from 'axios';
export const loginSystem = (data) => {
    return dispatch => {
        return axios.post('/user', {
            login: data.login,
            password: data.password
        })
   }
}

this.props.onLoginSystem(account).then((response) => {
   .... не работает
})

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim, 2017-05-24
@maxfarseer

Judging by the code, you decided to involve redux in this business as well, so you need to supplement your example with a reducer and read data from it.
off.documentation
tutorial on ru (outdated, but the essence itself has not changed)

S
Shane Matte, 2017-05-24
@mattedev

axios.post('/user', {
     login: data.login,
     password: data.password
}).then(({data})=>{
    store.dispatch({
        type:'ACTION',
        data
    })
})

D
davidnum95, 2017-05-24
@davidnum95

redux-thunk ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question