gpt4 book ai didi

reactjs - redux reselect 正在返回一个函数

转载 作者:行者123 更新时间:2023-12-05 04:01:43 24 4
gpt4 key购买 nike

由于一些奇怪的奇怪原因,我的重新选择选择器返回了这个函数:

ƒ () {
if (!areArgumentsShallowlyEqual(equalityCheck, lastArgs, arguments)) {
// apply arguments instead of spreading for performance.
lastResult = func.apply(null, arguments);
}

我不明白为什么要这样做。它应该返回一些 JSON,我可以用它在我的 ma​​pToProps 中进行映射。

我的 redux 映射很简单,看起来像这样:

const mapStateToProps = (state) => {
return {
initialValues: selectShop(state),
}
}

我的选择器文件如下所示:

import { createSelector } from 'reselect';

//shops selector
const selectDomain = () => state => (state ? state.shops : {});

export const selectShop = () =>
createSelector(
selectDomain(),
shops => {
let shop = shops.filter(shop => shop.selected);
return shop[0];
},
);

为什么我返回的是函数而不是 JSON?

最佳答案

您使用的 createSelector 有误。它实际上返回函数的内存版本。

像这样的东西应该可以工作

import { createSelector } from 'reselect';

//shops selector
const selectDomain = state => (state ? state.shops : []); // I've fixed it to return an array

export const selectShop = createSelector(
selectDomain,
// you could use find instead of `filter` herr
shops => shops.find(shop => shop.selected)
)

关于reactjs - redux reselect 正在返回一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55147272/

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