TypeError:无效的尝试重构不可迭代的实例

maj*_*deh 5 promise reactjs redux

我是这个项目的新手,正在尝试使用react-redux-universal-hot-exampleAPI,但是使用了我的代码:

export function showMessage() {
  return {
    type: SHOW_MESSAGE,
    promise: (client) => client.get('/posts')
  };
}
Run Code Online (Sandbox Code Playgroud)

我在浏览器中收到此错误:

TypeError: Invalid attempt to destructure non-iterable instance

有人可以帮忙吗?

Par*_*Roy 5

如果使用es6版本的For Of循环时遇到此问题,只需检查是否在数组上使用了.entries()

例:

for( const [item. index] of arr.entries() ) {
 console.log(index);
}
Run Code Online (Sandbox Code Playgroud)


小智 4

我遇到了同样的问题,查看后发现这是一个错字。你应该使用类型而不是类型,即:

export function showMessage() {
  return {
    types: [MESSAGE_FETCH, MESSAGE_FETCH_SUCCESS, MESSAGE_FETCH_FAIL],
    promise: (client) => client.get('/post')
  }
}
Run Code Online (Sandbox Code Playgroud)

请记住,当承诺得到解决时,“类型”数组将调度这些操作(成功或失败)。