cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pass typescript class as a parameter to navigation between pages

gilgi
DynaMight Champion
DynaMight Champion

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.

1 REPLY 1

sinisa_zubic
Dynatrace Champion
Dynatrace Champion

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

 

Featured Posts