Setting/getting temporary state is asynchronous?

When running the following code we get null logged:

const val = 1;
console.log('ts value is');

Is this the expected behavior? If so, how might we accomplish the following:

  • When the page loads, we need to get the current time and save it in a var
  • This time var will be used in queries throughout the page
  • Some of those queries run immediately on pageload....but they fail sometimes, because the temporary state time var does not yet exist (as seen above, it's null for some milliseconds after setting it)


This is normal behavior. See this post: When to use Temporary State vs. local variables


Hi @aviator22!

You can try setting the initial value of your temporary state value which will make it more immediately accessible.

As to the expected behavior - this question was brought up by @bradlymathews here. To summarize: ts.setValue returns a promise which you can await and then reference the new value with ts.value if you go to the 'Advanced' tab of your query and select this option:

Let me know if this works out for you!


Thanks folks, that clears it up

This doesn't seems like working when you import the app as module and run from parent app. Is it by design or a bug?

Tracking this bug here! Thanks for surfacing it :slightly_smiling_face: