Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to export a state in react native, and import it into another file? (NOT COMPONENT)

I am trying to export this state: const [jsonText, setJSONText] = useState(); out of my file. I tried a simple export const jsonText;, but that did not work at all. I tried looking it up, but they were all for components. Is there a way I can do this, and to keep making sure that the constant is still updating even when it’s in the other file? I tried passing it as a prop and that did not work.

Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

State can’t be import or export and only can be passed as a prop or by using context API.

You would advise you to learn about state and react in general.

Here are some resources:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading