I want to automatically run a JS Query whenever a global state variable (refreshSignal.value) changes.
Issue:
JS Queries don’t seem to react to changes in global state. Even when I reference {{ refreshSignal.value }} in the query or in the “Disable query” condition, the JS Query does not re-run when the variable updates. It only runs if I explicitly call .trigger(), or if I set it to run periodically / on page load.
Steps I’ve taken to troubleshoot:
Tried putting {{ refreshSignal.value }} in the JS Query directly.
Tried controlling with “Disable query” (e.g., {{ !refreshSignal.value }}).
Verified that refreshSignal.value is updating correctly.
Additional info:
Running on Retool Cloud.
My question: What’s the right way to make a JS Query automatically run when a global state changes?
This approach is a reliable workaround since JS queries don’t natively re-run/automatic run behavior on global state changes. It ensures your logic always stays in sync with updates to the variable without needing manual triggers each time.
Hope this clears things up and gives you a smooth way forward
I'm not sure of a "right way" but the workaround I use is to have a "dummy" JSON SQL query.
SQL queries will trigger when a variable value changes, whereas JS queries do not.
the json query triggers every time the global var changes. on success it runs my js query
the js query shows the notification with the new value of the global var