This is an example from reselect documents
const selectItemsByCategory = createSelector(
[
state => state.items,
(state, category) => category
],
(items, category) => items.filter(item => item.category === category)
)
usage on react
const myitems = useSelector(
(state) => selectItemsByCategory(state, 'CatName')
)
My question is, how can I pass more than one parameter?
const selectChildItemByNameAndCategoryName = createSelector(
[
selectItemsByCategory
(state, childName) => childName
],
(categories, childName) => categories.filter... using childName form results of selectItemsByCategory
)
how can I use it?
const myitems = useSelector(
(state) => selectChildItemByNameAndCategoryName(state, 'CatName', 'childName')
)
2
Answers
createSelector
always forwards all arguments to all input selectors.Output:
In your case you can simply just do this:
So in you component you can position the arguments in a similar order: