减速器中的Action.balance负载未更新物理余额

时间:2019-04-05 15:47:03

标签: reactjs redux reducers

在减速器中

传入的action.payload.balances显示正确的信息,但不会更新物理余额状态

我还要指出的是,当我尝试发送交易时,它将再次调用getBalances并知道我的用户界面显示的内容不足,这令人困惑为什么信息未直接更新到余额变量

Module

整个reducer文件

  // Sequence of events (all of these are in different files of course)    

  // Action Call
  export const getBalances = exchange => 
  action(actionTypes.GET_BALANCES.REQUEST, { exchange })

  // Request
  case GET_BALANCES.REQUEST:
    return { ...state, status: 'loading' }

  // Saga 
  export function* getBalances(action) {
    getBalanceCount++
    const state: storeType = yield select()
    yield fork(async, action, API.getBalances, {
      exchange: state.exchanges.selectedExchange._id,
      userId: state.auth.userId,
    })
    if (getBalanceCount > 1) {
      getBalanceCount--
      return
    }
    yield delay(10000)
    if (state.auth.token && state.auth.status === 'success')
      yield put({ type: action.type, payload: {} })
  }

  // API Call
  export const getBalances = ({ userId, exchange }) =>
  API.request(`/wallets/${userId}/${exchange}`, 'GET')

  // Sets balances to the payload.balances
  case GET_BALANCES.SUCCESS:
    return {
      ...state,
      balances: action.payload.balances,
      status: 'success',
    }

action.balances.payload:https://imgur.com/a/HuIKPT3

state.balances:https://imgur.com/a/GlzHg7v

我希望有效载荷能够更新余额,但是根本不这样做

所有内容的格式是否都能正确执行此操作?还是可能是JSON格式问题?

0 个答案:

没有答案