In my React-Native App; I have one const variable declared as below in one component named: constants.js
export const IS_VIA_DEEP_LINK = false
Now,
In my Splashscreen.js
I am doing as below:
constants.IS_VIA_DEEP_LINK=true;
When I try to access the value of IS_VIA_DEEP_LINK in the same Splashscreen.js
or any other functional component I get the updated value- true.
How is it possible?
2
Answers
The simplest way is use react-native-async-storage:
You can use 2 functions above in anywhere of your project
You cannot change the value of a primitive constant variable. Primitive types in JavaScript are
string
,number
,bigint
,boolean
,undefined
,symbol
, andnull
.1. Method
Define the
IS_VIA_DEEP_LINK
variable aslet
.2. Method
If you want to keep your variable as a constant put it in a object and export that object. Since objects are stored by reference, you can change their values even if the object defined as a constant.