0

将 toJS 与重新选择库一起使用时,我在反应应用程序的选择器中遇到错误。我尝试导入toJS和不导入它,无论如何我都会收到错误消息。

nodeCreationWindow.get(...).toJS 不是函数

import { createSelector } from 'reselect'
import { toJS } from 'immutable'

const selectNodeCreationWindow = () => (state) => state.get('nodeCreationWindow')

const selectNodes = () => createSelector(
  selectNodeCreationWindow(),
  (nodeCreationWindow) => {
    return nodeCreationWindow.get('nodes').toJS()
  }
)

const selectTags = () => createSelector(
  selectNodeCreationWindow(),
  (nodeCreationWindow) => nodeCreationWindow.get('tags').toJS()
)

const selectSuggestions = () => createSelector(
  selectNodeCreationWindow(),
  (nodeCreationWindow) => nodeCreationWindow.get('suggestions').toJS()
)


export {
  selectNodes,
  selectTags,
  selectSuggestions
}
4

1 回答 1

1

我认为返回的值nodeCreationWindow.get('nodes')已经是一个纯 JS 对象,所以它没有 toJS 方法。

此外,删除此行:

import { toJS } from 'immutable'

因为toJS不是由 Immutable 模块导出,而是附加到 Immutable 对象

于 2017-02-08T05:51:16.500 回答