Skip to content

refetch only part of loader with useFetcher #2259

Closed Answered by kiliman
ddavid67 asked this question in Q&A
Discussion options

You must be logged in to vote

Just add a querystring to your fetcher.load request. Then in your loader, you can return the specific data you want.

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.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ddavid67
Comment options

@kiliman
Comment options

Answer selected by ddavid67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants