“ TypeError:传播不可迭代实例的无效尝试”是什么意思,以及如何解决?

时间:2018-11-30 15:12:18

标签: react-native redux react-redux

以前该方法工作正常,但现在出现错误TypeError: Invalid attempt to spread non-iterable instancespread non-iterable instance是什么意思?

我正在打电话获取用户ID列表,然后遍历每个ID以获取添加convos,然后添加到redux。以前可以正常运行,现在会抛出上述错误。

      this.props.matchUserIds.matchUserIds.matchUserIds.map(id => {
          apiHelper.getProfileInfo(token, id).then(results => {
            const match = results.data.data
            match.isBlocked = false

            apiHelper.getConvoByUsers(this.props.currentUser.authToken, match.user.id)
              .then(results => {
                  if(results.data.data.length > 0) {
                    match.convoExists = true
                    match.convoId = results.data.data[0].id
                  } else {
                    match.convoExists = false
                  }

                  this.props.addMatchesProfile({matchUserProfiles: match})
  ...

MatchesActions.js

import {
  GET_MATCHES,
  ADD_MATCHES_PROFILES,
  RESET_MATCHES,
} from './types'

export const addMatchesProfile = ({ matchUserProfiles }) => {
  return {
    type: ADD_MATCHES_PROFILES,
    payload: { matchUserProfiles }
  }
}

MatchesReducer.js

import {
  GET_MATCHES,
  ADD_MATCHES_PROFILES,
  RESET_MATCHES,
} from '../actions/types'



const INITIAL_STATE = {
  matchUserIds: {},
  matchUserIdsLoaded: false,
  matchUserProfiles: {},
}

export default (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case GET_MATCHES:
      return {...state, matchUserIds: action.payload, matchUserIdsLoaded: true}
    case ADD_MATCHES_PROFILES:
      //error occurs here
      return {...state, matchUserProfiles: [...state.matchUserProfiles, action.payload]}
    case RESET_MATCHES:
      return {matchUserIds: INITIAL_STATE, matchUserProfiles: INITIAL_STATE}
    default:
      return state
  }
}

0 个答案:

没有答案