KennyUIowa KennyUIowa - 1 year ago 165
React JSX Question

Does React Native have global scope? If not, how can I mimic it?

I haven't been able to find anything like


for React Native and I want to share a couple variables between different Views.

Answer Source

Storing variables in the global scope is a bit of an anti-pattern in React. React is intended to be used with a one-way data flow, meaning data flows down from components to their children. This is achieved through the passing of props.

In order to share a value between multiple views, you would either need to store the data on a shared parent component and pass it down as a prop OR store it in a separate entity that is responsible for data management. In ReactJS this is achieved through libraries like Flux, but I'm not sure about the options for react-native.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download