Example of how to Memoize a filter function? #2334
Unanswered
ErikAGriffin
asked this question in
General
Replies: 2 comments 1 reply
-
Try this: |
Beta Was this translation helpful? Give feedback.
0 replies
-
Just declare the function at module level, not inside the component, this is a pure function no need to use a hook for it, whatever do not depend on a prop or state just declare it outside the component |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The documentation for
useFilter
states the following if passing a function to thefilter
property of a column:If a function is passed, it must be memoized
While my filtering seems to be working without memoizing the function, I understand it increases performance as the table grows and would like to do so. However, when attempting to wrap my function in
React.useMemo
I am getting errors.Here is roughly my filter function for the column:
filterValue
is an object in the form of{value: true, value2: true}
Here is how I have wrapped my filter function in React.useMemo
However when I do this, I get errors int he console that 'rows' is undefined. In fact, all of the arguments are undefined when the page loads. Any guidance on how to correctly memoize these functions?
Beta Was this translation helpful? Give feedback.
All reactions