Pass data from one screen to other

hello all,

I don’t know where to post my problem in react native.

I have 3 screens. On my first screen I have a upload image button. After completed upload image I set a variabl with a new value. Then I want my second or third screen get the this value. is it possible?


Hey @tenh!

Take a look at React Navigations’s docs, I think what you’re looking for is Navigation Prop Reference.

Good luck :slight_smile:

@charliecruzan Thank you, I’ve seen this but what i want is not navigate to specific screen. I want all screen get the value.

The link above that you linked means they go to Details screen and it can getparam only on this screen, other can’t.

I think setParams might be work in my case but I couldn’t make it work, any ideas?

You could always use Redux to share state between screens.

An example of using Redux with Expo can be found in this repo

Is there other ways not to use Redux?

@charliecruzan If it’s possible can you give me an example how to use redux to share state between screens? Have no idea after looking for a while.

Hey @tenh i am not an expert, just beginning with Expo.

But to my mind this question is more about React in general and what you are trying to achieve is totally what Redux offers.

If you don’t want to bother with full Redux you can try an implement Flux, which is supposed to be a bit easier when data stays skinny.

And of course if you don’t want to bother about any of these two, you can maybe store your information if the first common parent component and dispatch it as props to children.

For this one you will have to define the changing state function in the parent component and pass it along as props to children as well. Then every child will be able to execute a fonction that will change parent state.

I dont know if this trick is really clean or if it has any drawback but if your application stay really simple it is definitely something I would try.

I wish it could help a bit, good luck !

EDIT : You can have a look here, this is what I did to pass a markerPos prop to a map from my App component state (No redux or Flux just React)

react-flats/app.jsx at master · charlespernet/react-flats · GitHub

thank you

Hey, react context is a great thing to use in this particuler situation.