-
I would like to maintain a global state for the application, which sometimes should be read in a child components. Things like: App initialization happened or not. Are we in dark or light mode. Which authentication provider was used. Current themes selected. User claims...etc.
However, when I created a demo for this, I could not create a Scope variable (string, number or Symbol) and export it. The child component importing and using the scope value still only can read the default value of the global atom.
Stackblitz First try: https://stackblitz.com/edit/react-ts-x6dfq5 Fixed, single file example: https://stackblitz.com/edit/react-ts-ddqoms?file=Hello.tsx** |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The first example did not work, because I set the global value where I declared the Provider with the scope. I needed to create a new parent component, declare the Provider there and only set the values in child components. Fixed, single file example: https://stackblitz.com/edit/react-ts-ddqoms?file=Hello.tsx |
Beta Was this translation helpful? Give feedback.
The first example did not work, because I set the global value where I declared the Provider with the scope. I needed to create a new parent component, declare the Provider there and only set the values in child components.
Fixed, single file example: https://stackblitz.com/edit/react-ts-ddqoms?file=Hello.tsx