running a query only if a boolean is true

the component which Im running the query in is always mounted in app.tsx and I only want it to run a query when its opened, (the component is a modal)
8 Replies
kdiffin
kdiffinOP2y ago
kdiffin
kdiffinOP2y ago
heres the query code nevermind I got it, had to put a second object inside of the usequery with an enabled property set to my isOpen boolean
kdiffin
kdiffinOP2y ago
Gabriel
Gabriel2y ago
ABout this, If someone can explain... enabled: false means it will NOT execute the query ?
Neto
Neto2y ago
Yes As long it is a truthy value, will enable the query to continue If you open the devtools you will see a "disabled" tag on the query
higgsboz
higgsboz2y ago
To expand on the above, enabled: false just means that useQuery will not fire on mount. You can still call refetch() and it'll pull you're data
Gabriel
Gabriel2y ago
@higgsboz So basically It means that it will never be called by itself, but it can be called if you use refetch(). Ok cool
higgsboz
higgsboz2y ago
^ Correct
Want results from more Discord servers?
Add your server