Device Variables

Store persistent data on the user's device

Device Variable is a special kind of variable that is permanently stored on your users' devices using AsyncStorage from React Native. Device Variables can be set to any valid JSON and you can access Device Variables from anywhere in your app.

A Device Variable will not reset to the default value the next time the app starts. Instead, it will be the same value when the app is last closed. Use an App or Screen Variable to store ephemeral data.

For example, you might have a Device Variable named auth_token where you store a user's authentication token for making API requests. Storing this data in a Device Variable will ensure that the value persists across app launches.

⚠️

Republish after updating default values

If you need to change the default value of an Device Variable for a published app, you'll need to update the value in the Builder and then republish your app.

❗️

Don't set sensitive data as default values

Default values that you set for Device Variables are stored in your app's source code. You should usually never store private data such as API keys as default values in Device Variables.

Creating a Device Variable

To create variables, open the Variables modal from the top menu.

Configuration

ParameterDescription
NameThe name of the variable to be referenced.
Development ValueThe default value when building and publishing using the Development Environment
Production ValueThe default value when building and publishing using the Production Environment

📘

What type of value can you store in a Device Variable?

All JSON primitive value types can be stored inside a Device Variable. Learn more here.

Updating a Device Variable

Set Variable Action

To update the value of a Device Variable, you will use the Set Variable Action using the Action Editor.

For example, in the app below, we have already defined a Device Variable:

There is a Text component that displays the current value from the Device Variable on an example app screen. It uses the key of the Device Variable you defined in the previous step to map and display the value.

In scenarios where you want to display the value of a Device Variable, you can use its key and map it to the Input Text variable.

To update the value, on the Button below the Text component, add a new action called Set Variable. This action will update the value of the Device Variable to the value of the New Variable property.

In the current example, we're setting the value of the New Variable property to the Device Variable key and then using the Increment transform function that will increase the current value of the Device Variable.

Here is the final output:

In Custom Code

You can also work with App Variables in Files and Functions. Learn how in the Variables with Custom Code doc.