Device Variable is a special kind of Variable that is permanently stored on your users' devices using AsyncStorage from React Native. For example, a user's auth token is usually stored as a Device Variable. Device Variables can only be strings. However, you can optionally set a default value for a Device Variable (if you do not, it will default to an empty string
You can access Device Variables anywhere in your app you want to use data as a global variable.
However, unlike an App Variable, 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. Unlike App Variables, re-publishing an app currently does not affect Device Variables.
Each App Variable you create will have:
The name of the variable to be referenced.
The actual value of the variable (e.g., auth token).
What type of value you can store in a Device Variable?
All JSON primitive value types can be stored inside a Device Variable. Learn more here.
To update the value of a Device Variable, you will use the Action Set Variable from the Properties Panel > Interactions tab (fourth tab).
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:
Updated about 1 month ago