App Variables
Store data to use throughout your app
App Variables are shared pieces of data that live at the app-level and can be set and used across your entire app. They are useful for storing data that is common to all users or different parts of your UI. App Variables can be set to any valid JSON and you can access App Variables from anywhere in your app.
Each time your App restarts, the App Variable will reset to the default value. That means you shouldn't store information that needs to persist across app launches - use a Device Variable instead.
For example, you might have a variable named error_message
that you can set and access across all Screens in your app to display an error message in a Text component. Or use it to store the state of a Modal.
Republish after updating default values
If you need to change the default value of an App 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 App Variables are stored in your app's source code and bundle making it possible for bad actors to access and abuse the data. You should usually never store private data such as API keys as default values in App Variables.
Creating an App Variable
To create variables, open the Variables modal from the left menu bar of the Builder.
Configuration
Parameter | Description |
---|---|
Name | The name of the variable to be referenced. |
Development Value | The default value when building and publishing using the Development Environment |
Production Value | The default value when building and publishing using the Production Environment |
What type of value can you store in an App Variable?
All JSON primitive value types can be stored inside an App Variable. Learn more here.
Updating an App Variable
Set Variable Action
To update the value of an App Variable, you will use the Set Variable Action from a Trigger in the Interactions tab from the right panel of the Builder.
In Custom Code
You can also work with App Variables in Files and Functions. Learn how in the Variables with Custom Code doc.
Updated 4 months ago