redux reselect返回函数 [英] redux reselect is returning a function
本文介绍了redux reselect返回函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
出于某些奇怪的奇怪原因,我的重选选择器正在返回此函数:
For some strange weird reason my reselect selector is returning this function :
ƒ () {
if (!areArgumentsShallowlyEqual(equalityCheck, lastArgs, arguments)) {
// apply arguments instead of spreading for performance.
lastResult = func.apply(null, arguments);
}
我不明白为什么要这么做.它应该返回一些JSON,可用于在 mapToProps 中进行映射.
I do not understand why it is doing this. It is supposed to return some JSON which I can use to map in my mapToProps.
我的redux映射非常简单,看起来像这样:
My redux mapping is simple enough and looks like this :
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?
Why am I getting a function returned instead of JSON?
推荐答案
您使用的createSelector
错误.实际上,它返回一个函数的记忆版本.
You are using createSelector
wrong. It actually returns a memoized version of a function.
类似的事情应该起作用
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)
)
这篇关于redux reselect返回函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文