Skip to content

imperative fetching pattern #3622

Answered by TkDodo
seanbruce asked this question in Q&A
May 18, 2022 · 3 comments · 6 replies
Discussion options

You must be logged in to vote

i think it's a perfectly valid example for a search form, that, when submitted, should trigger a fetch. The idea is still relatively simple / declarative: only set searchStr when the user submits the form. That means you might need some state-duplication, but it's actually good in this example because it is two different states:

  1. the form state that represent the input field values. This is ephemeral client state, local to the form. can also be an uncontrolled input
  2. the "applied" filter state - the current value once the user has clicked apply. This is what react-query is interested in. A good place to store this is in the url, because it's globally available, only changes when the user c…

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@seanbruce
Comment options

@TkDodo
Comment options

@seanbruce
Comment options

@TkDodo
Comment options

@seanbruce
Comment options

Answer selected by seanbruce
Comment options

You must be logged in to vote
1 reply
@alwyntan
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants