shinzou
shinzou

Reputation: 6222

Signleton between different components in React Native

I want to have some object to be accessible from multiple components, the same object, and those components are independent of each other.

It looks like Redux isn't the right way and this: React native- Best way to create singleton pattern doesn't really answer the question.

Is there another way?

Upvotes: 0

Views: 550

Answers (1)

Roy
Roy

Reputation: 736

Well, I'm not sure this is right way but I usually do this way through module.

// config.js
export default {
    data1: 'data1',
    data2: 'data2',
    ...
}

// from components

import Config from './config' // You can do this easier with @providesModule
...
config.data1 // you now access & modify common datas like this

Upvotes: 1

Related Questions