createSelector call other selector with parmeter returned from the state #3499
-
Hi, I'm trying to achieve the same with selectors, but I don't know how to call the dependant selector with a parameter returned from the state.
here is what I tried but it's failing with state is undefined.
this is the stack trace, what am I doing wrong?
|
Beta Was this translation helpful? Give feedback.
Answered by
david-shortman
Jul 25, 2022
Replies: 1 comment 1 reply
-
Two ways to go about this. One, I explained in this thread. You can create a selector that delays the collection of a parameter. Second, you could get a reference to the global state and provide it to the selector: export const selectProductByIdWithRelatedProducts = (key: string) => createSelector(
state => state, // select global state
selectProducts,
selectProductById(key),
(globalState, productState, currentProduct) => {
if (currentProduct && currentProduct.collection && productState) {
return {...currentProduct, relatedProducts: selectProductsByCollection(currentProduct.collection.key)(state)}
}
}
); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
nep7un
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two ways to go about this. One, I explained in this thread. You can create a selector that delays the collection of a parameter.
Second, you could get a reference to the global state and provide it to the selector: