Javascript 从选择器访问道具';s结果函数
我有一个与文档中类似的用例,但是在我的例子中,Javascript 从选择器访问道具';s结果函数,javascript,reactjs,redux,react-redux,Javascript,Reactjs,Redux,React Redux,我有一个与文档中类似的用例,但是在我的例子中,visibilityFilter来自于道具。有没有一种方法可以实现下面这样的目标 export const getVisibleTodos = createSelector( getTodos, (todos, props) => { // props is undefined Props (or ownProps) is the second argument passed to any mapStateToProps fun
visibilityFilter
来自于道具。有没有一种方法可以实现下面这样的目标
export const getVisibleTodos = createSelector(
getTodos,
(todos, props) => {
// props is undefined Props (or ownProps
) is the second argument passed to any mapStateToProps
function.
Using that, you can extract the property you want as one of the inputs to your resultFunc
.
export const getVisibleTodos = createSelector(
getTodos,
(state, props) => props.visibilityFilter,
(todos, visibilityFilter) => {
switch (visibilityFilter) {
case 'SHOW_ALL':
return todos
case 'SHOW_COMPLETED':
return todos.filter(t => t.completed)
case 'SHOW_ACTIVE':
return todos.filter(t => !t.completed)
}
}
)
导出常量getVisibleTodos=createSelector(
盖托多斯,
(待办事项、道具)=>{
//道具未定义
使用它,您可以提取所需的属性作为resultFunc
的输入之一
使用它,您可以提取所需的属性作为resultFunc
的输入之一