Skip to content

How to call same query X number of times with different variable values and get updated result? #1237

Answered by budde377
Dave-Milind asked this question in Q&A
Discussion options

You must be logged in to vote

You can do something like this:

class SearchPage extends HookWidget {
  Widget build(BuildContext ctx) {
    const value = useState("");
    const result = useQuery(QueryOptions(..., variables: {'q': value.value})); // Will fetch when state changes
    return Column(children: [
      SearchBar(value: value), // Render search bar and update ValueNotifier on change
      Results(results: results) // Render results
    ]);
  }
}

This is intentionally a simplified example. In reality, you probably want to work with TextEditingController, but the principle of updating the state is the same.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Dave-Milind
Comment options

Answer selected by vincenzopalazzo
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