throwaway2908457
throwaway2908457

Reputation: 27

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.

Upvotes: 0

Views: 1386

Answers (1)

Yedidya Rashi
Yedidya Rashi

Reputation: 1094

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

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

Here are some resources:

Upvotes: 1

Related Questions