Reputation: 1259
Is it good idea to use global variables for communication between 2 components in react.js. Or is it bad practice.
If no, can somebody explains, whats are the drawbacks of it.
Thanks
Upvotes: 1
Views: 968
Reputation: 139
One of the core value propositions of React is one way data flow. Among other benefits, it makes it easy for developers to reason about as they trace the data flow. You don't want child-child communication, instead I would suggest structuring your app such that the parent can pass data to both children.
Upvotes: 1