From 02d157cb90e98216dce28fba77833e7fe1e271e3 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Tue, 31 Oct 2023 21:30:17 -0400 Subject: [PATCH] Add example of arguments mapping --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index ef6ded2c3..0074f3d77 100644 --- a/README.md +++ b/README.md @@ -531,6 +531,17 @@ A: Yes. Reselect has no dependencies on any other package, so although it was de ### Q: How do I create a selector that takes an argument? +Conceptually, Reselect works like this internally: + +```ts +const finalSelector = (...args) => { + const extractedValues = inputFunctions.map(input => input(...args)); + return output(...extractedValues); +} +``` + +In other words, all the arguments passed to the selector function are immediately passed to all of the inputs. + As shown in the API reference section above, provide input selectors that extract the arguments and forward them to the output selector for calculation: ```js @@ -546,6 +557,7 @@ const selectItemsByCategory = createSelector( ) ``` + More generally, you can have N arguments passed to the selector, and you can have M input functions extracting values from any of those arguments. All M extracted values get passed to the output function. ### Q: The default memoization function is no good, can I use a different one?