用参数重复使用选择器

如何将其他参数传输到组合选择器? 我试着

* 数据获取

* 数据过滤

* 将自定义含义添加到我的数据集中 / 组数据 myValue


export const allData = state => state.dataTable
export const filterText = state => state.filter.get/'text'/

export const selectAllData = createSelector/
allData,
/data/ => data
/

export const selectAllDataFiltered = createSelector/
[ selectAllData, filterText ],
/data, text/ => {
return data.filter/item => {
return item.name === text
}/
}
/

export const selectWithValue = createSelector/
[ selectAllDataFiltered ],
/data, myValue/ => {
console.log/myValue/
return data
}
/

let data = selectWithValue/state, 'myValue'/



console.log/myValue/

回报
undefined
已邀请:

风见雨下

赞同来自:

对您的问题的答案有详细描述 FAQ 这里:
https://github.com/reactjs/res ... ument
简而言之, reselect 不支持传输给选择器的任意参数。 推荐的方法是存储相同的数据而不是传输参数 Redux.

冰洋

赞同来自:

来自选择器的功能退款呢?
getFilteredToDos

这是一个例子


// redux part
const state = {
todos: [
{ state: 'done', text: 'foo' },
{ state: 'time out', text: 'bar' },
],
};

// selector for todos
const getToDos = createSelector/
getState,
/state/ => state.todos,
/;

// selector for filtered todos
const getFilteredToDos = createSelector/
getToDos,
/todos/ => /todoState/ => todos.filter//toDo/ => toDo.state === todoState/;
/;

// and in component
const mapStateToProps = /state, ownProps/ => /{
...ownProps,
doneToDos: getFilteredToDos///'done'/
}/;

江南孤鹜

赞同来自:

另一个变体:


const parameterizedSelector = /state, someParam/ => createSelector/
[otherSelector],
/otherSelectorResult/ => someParam + otherSelectorResult
/;


然后使用方法


const mapStateToProps = state => /{
parameterizedSelectorResult: parameterizedSelector/state, 'hello'/
}/;


虽然我不确定记忆/在这种情况下表现,但它有效。

冰洋

赞同来自:

这是我的方法。 使用参数和返回函数创建功能
reselect

.


export const selectWithValue = /CUSTOM_PARAMETER/ => createSelector/
selectAllDataFiltered,
/data/ => {
console.log/CUSTOM_PARAMETER/
return data
}
/

const data = selectWithValue/'myValue'//myState/;

要回复问题请先登录注册