-
In the doc there is an example with useFetcher usage with a combobox. useFetcher will reload all combobox data, even if I am searching in only one combobox ? This is not great at server side as it will do unnecessary database requests. Is there a way to optimize this ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Just add a querystring to your fetcher.load('/route?filter=option1') const url = new URL(request.url)
const filter = url.searchParams.get('filter')
let data
switch (filter) {
case 'option1':
data = await getOption1()
break
case 'option2':
data = await getOption2()
break
default:
data = await getAll()
}
return json(data) Although this is possible, it might be better to create a separate resource route for this. You can import the same data functions in both the route and the resource. |
Beta Was this translation helpful? Give feedback.
Just add a querystring to your
fetcher.load
request. Then in your loader, you can return the specific data you want.Although this is possible, it might be better to create a separate resource route for this. You can import the same data functions in both the route and the resource.