使用带参数的重选选择器 [英] Use reselect selector with parameters

查看:90
本文介绍了使用带参数的重选选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将其他参数传递给组合选择器?我正在尝试

How do I pass additional parameters to combined selectors? I am trying to

•获取数据

•过滤数据

•通过myValue为我的数据集/组数据添加自定义值

• Add custom value to my data set / group data by 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

推荐答案

您的问题的答案是详细的在这里的常见问题解答中: https://github.com/reactjs/reselect#q-how-do-i-create-a-sele ctor-that-take-an-argument

The answer to your questions is detailed in an FAQ here: https://github.com/reactjs/reselect#q-how-do-i-create-a-selector-that-takes-an-argument

简而言之,重新选择不支持传递给选择器的任意参数。建议的方法是,将相同的数据存储在Redux状态,而不是传递参数。

In short, reselect doesn't support arbitrary arguments passed to selectors. The recommended approach is, instead of passing an argument, store that same data in your Redux state.

这篇关于使用带参数的重选选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆