Redux - how to call an action and wait until it is resolved

前端 未结 2 493
鱼传尺愫
鱼传尺愫 2021-01-05 17:24

I\'m using react native + redux + redux-thunk I do not have much experience with redux and react native

I\'m calling an action inside my component.

         


        
2条回答
  •  逝去的感伤
    2021-01-05 18:09

    I don't understand the problem, but maybe this could help

    export const checkClient = (cliente) => {
      return dispatch => {
        dispatch({type: CHECK_CLIENT_PENDING });
    
        axios.get(`${API_HOST}/api/checkclient`, header).then(response => {
    
            dispatch({type: CHECK_CLIENT, payload: response.data }); //valid or invalid
    
        }).catch((error) => {  });
    
       }
    }
    

    ...


     this.props.checkClient(cliente);
    
     if(this.props.clienteIsPending){
      ...
     }
    
     if(this.props.clienteIsValid){
      ...
     }
    

提交回复
热议问题