如何解决未捕获的错误 createSelector 方法?
How to resolve uncaught error createSelector method?
我在我的 Angular 应用程序中使用 selector,但在调用 selector 时遇到未捕获的错误。尽管我已经提供了必需的 select 或函数作为 createSelector
的参数。根据此处的重新 select 文档 - https://github.com/reduxjs/reselect
Uncaught Error: Selector creators expect all input-selectors to be functions,
instead received the following types: [object]
我确实在这里发现了一个类似的问题,它建议将 selector 从箭头函数更改为普通函数声明可以修复它。为了解决函数声明的任何提升问题,但这并不能解决未捕获的错误 -
https://github.com/reduxjs/reselect/issues/169
通过传入store.getState()
作为参数调用selector:
let state = getBookTitles(this.store.getState());
问题:
调用 re-select 的 createSelector
时如何解决未捕获的错误?
这是我的 Selectors.js 文件,其中包含应用状态 select 或者:
// Selectors.js
import { createSelector } from 'reselect';
function selectBooks(state: any) {
return state ? state.books: [];
}
function selectBookTitles(books: any) {
return books ? books.titles: [];
}
// bookTitle selector
export let getBookTitles = createSelector(
selectBooks,
selectBookTitles,
);
原来错误来自 selector.js
文件中错误定义的选择器。
错误:
Uncaught Error: Selector creators expect all input-selectors to be functions,
instead received the following types: [object]
语法错误:
export const selectConfig = createSelector(
[initialSettingsState.config],
'config',
);
正确的语法:
const configSelector = state => {
return state ? state.config: [];
};
export const getConfig = createSelector(
configSelector,
config=> {
return config;
},
);
我在我的 Angular 应用程序中使用 selector,但在调用 selector 时遇到未捕获的错误。尽管我已经提供了必需的 select 或函数作为 createSelector
的参数。根据此处的重新 select 文档 - https://github.com/reduxjs/reselect
Uncaught Error: Selector creators expect all input-selectors to be functions,
instead received the following types: [object]
我确实在这里发现了一个类似的问题,它建议将 selector 从箭头函数更改为普通函数声明可以修复它。为了解决函数声明的任何提升问题,但这并不能解决未捕获的错误 - https://github.com/reduxjs/reselect/issues/169
通过传入store.getState()
作为参数调用selector:
let state = getBookTitles(this.store.getState());
问题:
调用 re-select 的 createSelector
时如何解决未捕获的错误?
这是我的 Selectors.js 文件,其中包含应用状态 select 或者:
// Selectors.js
import { createSelector } from 'reselect';
function selectBooks(state: any) {
return state ? state.books: [];
}
function selectBookTitles(books: any) {
return books ? books.titles: [];
}
// bookTitle selector
export let getBookTitles = createSelector(
selectBooks,
selectBookTitles,
);
原来错误来自 selector.js
文件中错误定义的选择器。
错误:
Uncaught Error: Selector creators expect all input-selectors to be functions,
instead received the following types: [object]
语法错误:
export const selectConfig = createSelector(
[initialSettingsState.config],
'config',
);
正确的语法:
const configSelector = state => {
return state ? state.config: [];
};
export const getConfig = createSelector(
configSelector,
config=> {
return config;
},
);