Trying to avoid prop drilling with filtered list. #2542
Replies: 2 comments
-
I don't think that advice applies to every situation. passing props is the most explicit way of defining dependencies. I see nothing wrong with the above code. Yes, "drilling" props down over lots of layers ("lots" depends on your pain threshold) can become cumbersome. To absolutely avoid it, you would have to make
where |
Beta Was this translation helpful? Give feedback.
-
It would be nice to have for example |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I have this situation:
It kinda looks like this:
The
useGetFilteredContent
is my reusable react-query hook. I Include the filters into my queryKey in order for it to refetch every time a filter is updated.I read somewhere that one should avoid prop drilling but I don't see a way how to do that in this case. If I would define the hook in the content component It wouldn't know about the filters set in the header component.
This is also true for all possible mutations I want to define. If I want to do optimistic updates on the filtered list it needs to know about the filters. Which means I have to define all mutation hooks in the parent component and pass it down 1-2-3 times until I arrive at my 'delete item button component' for example.
The more complex my application gets the more tedious the prop drilling gets. So I am looking for a way to avoid it.
Beta Was this translation helpful? Give feedback.
All reactions