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

Time:07-01

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.

CodePudding user response:

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:

  • Related