Skip to content
MyAppBuilder
StableGuide

App state variables

State is what your app remembers while people use it : the location they selected, the tab that is open, the items in a cart, a filter. App state is shared by every page; page state lives only while a page is open and resets when the visitor leaves it.

App state variables

State is what your app remembers while people use it: the location they selected, the tab that is open, the items in a cart, a filter. App state is shared by every page; page state lives only while a page is open and resets when the visitor leaves it.

Variables are declared in Logic → App state so that the data picker can offer them by name, and so they have a type and a default value.

When to use

  • A value chosen on one page must be used on another (app state): a selected branch, a date range, a cart.
  • A control on a page needs to remember something while the page is open (page state): which tab is active, whether a panel is expanded.
  • You want a counter or toggle changed by buttons.

How to add a variable

  1. Open Logic → App state.
  2. Choose App state or Page state (for page state, pick the page).
  3. Click Add variable.
  4. Enter a Key (letters, numbers and underscores; cannot start with a number), for example selectedLocation.
  5. Choose a Type: Text, Number, Yes / no, JSON object or List.
  6. Optionally enter a Default value (lists and JSON objects are typed as JSON, e.g. ["a", "b"]).
  7. Tick Remember in the visitor's browser (survives reloads) if the value should persist between visits on the same device.
  8. Add a short Description and click Add variable.

Edit a variable with the pencil icon; delete it with the bin icon. Deleting (or renaming) a key breaks every binding and action that uses it, so update those first.

Reading and changing state

  • Read it anywhere a data picker is offered: App state › selectedLocation or Page state › tab. In templates write {{state.selectedLocation}} (or {{app.…}}) and {{pageState.tab}}.
  • Change it with the Set state action (any value, including bindings) or Increase / decrease state for numbers. Both actions let you choose App state, Page state or Component state and the key; when app variables exist, the key is a dropdown.
Example
Button "Berlin"   onClick → Set state: App state › selectedLocation = "berlin"
Table "Bookings"  Data filter: Location equals App state › selectedLocation
Button "+"        onClick → Increase / decrease state: App state › qty by 1

Component state

Components such as forms, tables and modals expose their own state (values, selected record, page, open). It is not declared here; pick it directly in the data picker under the component's name, or target it with Set state → Component state.

Common mistakes

  • Using a key before declaring it. Set state works with any key, but the data picker only lists declared variables, and defaults only apply to declared ones.
  • Expecting page state to survive navigation. It resets when the visitor leaves the page; use app state instead.
  • Storing sensitive data in persisted state. Persisted values live in the visitor's browser storage.
  • Mismatched types. A Number variable set to text still stores text; keep Set state values consistent with the type.

Advanced

Variables are { key, type, defaultValue?, persist?, description? } under project.appState or page.pageState, managed by the create_state_variable, update_state_variable and delete_state_variable commands. State values are evaluated in the browser; server actions receive a snapshot of app, page and component state so bindings in their fields resolve the same way.

Related

Was this helpful?