-
Hey, I've created a combobox using The interesting part is getting the data back from the server. Well, inside the combobox component I use simply Right know I propagate returned data using a callback and as I only need to access that data one level higher it's not an issue but what if I need that data somewhere else? Is there a way to get that data directly from the resource route? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Ideally, you move the useFetcher to a parent component of all your components needing the data, and then share it through props or context. There's also an Side question, why are you using a POST to do a search? It would be simpler to do |
Beta Was this translation helpful? Give feedback.
Ideally, you move the useFetcher to a parent component of all your components needing the data, and then share it through props or context.
There's also an
useFetchers()
hook (note the plural) which returns the list of fetchers, similar to useMatches, but there's no simple way to identify a specific fetcher, you will have to do afetcher.find
and check if one of them has the data you need.Side question, why are you using a POST to do a search? It would be simpler to do
fetcher.load(
/route?term=${encodeURIComponent(term})
and do a GET request, with the benefit that Remix will not re-load all routes loaders after every request (when there's a POST against an action, Remix will revalidate …