How do I properly define and use state variables in Retool? Getting 'state is not defined' error

Hi everyone,
I'm trying to implement a login modal in Retool that opens conditionally based on user authentication.

In various guides, I see expressions like: {{ !state.loggedInUser.value?.email }}.

But when I use this, I get the error: "state is not defined".

Here’s what I’ve done so far:

  • Created a temporary state variable called loggedInUser with an initial value of {}.
  • I tried using "state.loggedInUser" under a modal’s visibility condition.
  • Also attempted to access it in JS queries and components.
  • Refreshing the app as mentioned here.

I’m unsure if I'm missing a setup step for state variables, or if I should be referencing them differently (e.g., variables.loggedInUser or something else?).

Any help, please? I feel disappointed :frowning:

Hi there @majhol3 and welcome to the forum!

You can access your variable's data using the following: loggedInUser.value this will return whatever value is stored within it.

If I misunderstood the question completely, do share a screenshot of your setup.

Best,
Miguel

1 Like

Thank You

1 Like