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
kdiffin14mo ago
kdiffin
kdiffin14mo 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
kdiffin14mo ago
GBianchi
GBianchi14mo ago
ABout this, If someone can explain... enabled: false means it will NOT execute the query ?
Neto
Neto14mo 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
higgsboz13mo 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
GBianchi
GBianchi13mo 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
higgsboz13mo ago
^ Correct