Manual filtering and extracting the filter state #408
Unanswered
thomas-tran-de
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I want to use the filter state outside MRT and got a little stuck.
As far as I understand, I need both the
columnFilters
and thecolumnFilterFns
to determine which filters to apply. I use both states to create a DB query inmapMrtToApiFilters
.My idea is to do something like this:
However, I ran into an issue. When updating the filter functions, the following happens:
handleColumnFilterFnsChange
is called and correctly updatesfilters
.handleColumnFiltersChange
is called and overwritesfilters
with the previous filter function.This means that the filter functions used in
filters
always lack one value behind. What am I missing? The issue is not inmapMrtToApiFilters
. I already replaced it by a simple console log without anything else.Right now, my workaround is to add an if condition to
handleColumnFiltersChange
:Another solution I can think of is introducing
useEffect
. But it feels wrong to use it here, because I have access to the onChange handlers. In my understanding,useEffect
should only be used if I have no other way of knowing when a state changes, e.g., because it depends on an external system.I appreciate your suggestions 🙏
Beta Was this translation helpful? Give feedback.
All reactions