App State variables

Set temporary state values

State variables function as temporary storage while users interact with your app. They reset to their initial values upon a page refresh or when the app is closed. State variables persist solely within a single page.

For persistent storage that remains intact upon page reloads, consider exploring the Local Storage documentation.

State variables come in two scopes: app and page. App scope variables maintain their values across different pages, while page scope variables retain their values only within the specific page.

A state variable can possess the following attributes:

  • Name - the unique identifier;

  • Type - string|number|boolean|object|arrray;

  • Initial value - the starting value of the variable.

State variables can be organized using the folder structure of the Actions panel, allowing you to place relevant variables near the actions and logic they are associated with.

Creating a state variable

To create a state variable, follow these steps:

  1. On the Actions panel, click the + button to add a new item and select State Variable in the dropdown menu.

  2. Give your variable a name, and assign its initial value.

  3. Click Save.

Depending on the scope in which the variable is created, it is now available either in the whole app or on a particular page.

Now this variable is available in your UI Bakery app. You can read and write to this variable.

Working with a state variable

Upon creating a state variable, it becomes accessible within the app.

You can assign a value to the variable using the "Save to State" action or directly through JavaScript code blocks.

Read variable value

Within the app, all variables can be accessed using the {{state.<variableName>}} scope:

Save to State action

To store a value within an action, follow these steps using the Save to State action step:

  1. Choose Save to State.

  2. Select the variable you wish to modify.

  3. Define a new value, which can either be hardcoded or derived from an available variable, such as {{data}} to reference the result of a previous action step, or {{ui.component.value}} to access a component's state.

Save and reset variable value with code

Additionally, you can save state values in any JavaScript code block:

state.varName = 'newValue';

// or using setValue method
state.setValue('varName', 'newValue');

read with the state.getValue method:

const value = state.getValue('varName');

reset a variable to the initial value:


or reset all variables:

// reset all variables, page and app state

// reset all page variables

// reset all app (global) variables

Use case: resetting a text field after sending the data

Let's check how to use a state variable on an example. Say you have a text component and would like to reset its' value after a comment is left. Here's how to do that:

  1. Create a state variable of a string type.

  2. Assign the state variable to the text Value field:

3. Create a Save to State action, that will save the new comment and assign it to the On Change trigger of the text component:

4. Next, add another Save to State action, that will reset the comment:

5. Finally, drag a button onto the working area and assign the reset action on its On Click trigger.

Last updated