How to call same query X number of times with different variable values and get updated result? #1237
-
Hello, first of all, I would like to thanks that this package/library is very easy to use and very helpful. I am using it for making queries and mutations in flutter and it is very simple to implement. But now I am stuck on a situation/problem which I am not able to understand how to implement using this package/library. I have a search bar, and I am supposed to make a query call whenever the user enters a value in the searchbar, to get updated list of suggestions/options from the query. Can someone please help/guide me how can I make fresh query calls with new/updated variables and get the updated result? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 |
Beta Was this translation helpful? Give feedback.
You can do something like this:
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.