Intro to Variables

Variables allow you to store and use pieces of data in your app

Variable Types

There are four types of variables available that you can use inside a Draftbit app.

Variable TypeDescription
App VariablesVariables that can be set and used throughout your entire application.

Each time your app restarts, this type of variable will reset to its default value.

Useful for storing constants as a default value or other app-wide, non-user-specific, data such as an error_message or to store the state of a Modal.
Device VariablesVariables that allow you to store data on your app users' devices that can be used throughout your app.

Each time your app restarts, this type of variable will not reset to the default value and will use the last value stored in it.

Useful for storing user-specific data that needs to persist across sessions, such as an auth_token after login.
Screen VariablesVariables that are scoped to the Screen on which they are created.

Each time the app restarts or the Screen is removed from the navigation stack, this value will be reset to its default value.

Useful for storing Screen-specific data, such as variables associated with various input components for a form.
System VariablesSystem-generated variables that come with a pre-defined value such as Is Online, Is iOS, and Device Width.

Creating a Variable

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

JSON Data Format

All variables available in Draftbit can be assigned valid JSON data. You can use this free service to make sure you're value is valid JSON.

Strings

Example:

"Hello World"

Numbers

Example:

99

3.33

Booleans

Example:

true

Objects

Example:

{"name": "Dave"}

{"address": {"city": "Austin", "state": "Texas"}}

Arrays

Example:

["violet", "indigo"]

[{"name": "Dave"}, {"name": "Rahul"}]


What’s Next

Learn about the different types of variables available to you