Hay una acción creada usando createAsyncThunk y este método devuelve una promesa que se maneja así
export const action = createAsyncThunk( '/fullfilment/update-content-preference', async (data, { getState }, thunkAPI) => { try { const state = getState(); const authToken = state.auth.token; const { selectedShipmentId: shipmentId } = state.fullfilment; const obj = { ...data, shipmentId }; const response = await axios.post( '/fullfilment/update-content-preference', obj, { headers: { Authorization: `Bearer ${authToken}` } } ); return response; } catch (err) { if (err.response) { return thunkAPI.rejectWithValue({ err: err.response, status: err.response.status }); } return thunkAPI.rejectWithValue({ err: 'Network Error' }); } } );y abajo estan las promesas que se manejan
[action.pending]: state => ({ ...state, loading: true }), [action.fulfilled]: (state, action) => ({ ...state, data: { ...state.data, loading: false, list: action.payload.data.list message: action.payload.data.message } }), [action.rejected]: (state, action) => ({ ...state, loading: false error: action.payload.data.error message: action.payload.data.message })pendiente resuelto y rechazado, todo funciona bien, pero en rechazo no puedo obtener los datos, pero donde la acción está enviando thunkApi con error, estoy obteniendo datos allí, ¿por qué no en la promesa rechazada? Cualquier ayuda será apreciada, gracias
Pasaste err a rejected pero olvidaste usarlo.
error: action.payload.err.data.error message: action.payload.err.data.message Y estás declarando thunkAPI manera incorrecta. Solo actualiza así:
async (data, thunkAPI) => { const { getState } = thunkAPI; }