Global state in React Native

I usually create a global.js containing:

module.exports = {
   screen1: null,
};

And get the value of the state on the screen

import GLOBAL from './global.js'

constructor() {

    GLOBAL.screen1 = this;

}

Now you can use it anywhere like so:

GLOBAL.screen1.setState({
    var: value
});

Leave a Comment