01 Nov 2023 02:43 PM - edited 01 Nov 2023 03:27 PM
Hi,
As a newbee to TypeScript: I have created a custom typescript class and I need to pass an instance of it from one page to the other. Is it even possible?
I know I can pass JsonObject using the useNavigate hook for example but this will not include all of the class functionalities.
How would you handle this? Should it just be as a single page with different components rendered based on the state of it and using "global" page variable with the class instance?
Gil.
Solved! Go to Solution.
02 Nov 2023 07:41 AM
Hi @gilgi
This is a question about how to manage states within React.
If you don't have a complex component structure, you can share the states between components by lifting the state up and passing props. Please check out this page for more detailed examples: https://react.dev/learn/sharing-state-between-components
For more complex component structure I would suggest that you use context: https://react.dev/learn/passing-data-deeply-with-context
BR,
Sini