gpt4 book ai didi

javascript - React reselect - toJS 不是一个函数

转载 作者:行者123 更新时间:2023-12-03 05:03:37 27 4
gpt4 key购买 nike

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

nodeCreationWindow.get(...).toJS is not a function

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
}

最佳答案

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

此外,删除此行:

import { toJS } from 'immutable'

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

关于javascript - React reselect - toJS 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42104349/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com