Search code examples
react-nativereact-native-router-flux

Communicate between two unrelated components


How do you handle communication between components with no common parent in react-native ?

What's the best way to communicate between two unrelated components ?

I did some research and the most recommended way seems to be using context https://reactjs.org/docs/context.html.


Solution

  • There are multiples way to handle a global state, one of them is the new React Context API, but one of the most famous is redux, written by Dan Abramov, who works at Facebook, inspired by flux, an old facebook library to manage global state. There is also Mobx and many others, I suggest you take a look at each one and see what fits you best, it's hard to tell you without knowing your problem. Feel free to ask any other question about one of them