How to access the array of one component in another component in React Native? | SoloLearn: Learn to code for FREE!

+2

How to access the array of one component in another component in React Native?

4/23/2020 12:39:06 PM

cmcodes

1 Answer

New Answer

+5

I am assuming you are refering to sibling components OR accessing a state of a child from it's parent (those are the tricky ones) One way to go about it is having the state defined on a top level and passed along as props along with a function to update it. That's a rather straightforward solution. A better way that will require some refactoring (and some extra learning) is to add a global state management to the project, such as Redux, Mobx or any other (there are plenty out there) Redux is one of the most popular today, and Mobx is a personal favorite of mine.