Hildebrandt Tobias
10/07/2024, 2:02 PM<Route
path='/dashboard'
render={(props) => <Dashboard {...props} isAuthed={true} />}
/>
The RouteObject
doesn't expose a render
field.turansky
10/07/2024, 3:35 PMRouteObject.element
is render result.
You can use it.
RouteObject(
element = MyPage.create { /* my props */ }
)
turansky
10/07/2024, 3:36 PMContext
to pass configuration, to avoid redundant renders.Hildebrandt Tobias
10/08/2024, 7:35 AMrender
to prevent redundant renders.
But element
would rerender every time as I understand it?
I wanted to pass different Props
for different routes since I want to reuse
the same component just with differents items (example):
fun exampleRoutes() = jso<RouteObject> {
path = "production"
Component = SubDrawer { drawerItems = productionDrawerItems } // This doesn't work
ErrorBoundary = ErrorView
children = arrayOf(
jso {
path = "plan"
Component = ProductionPlanView
ErrorBoundary = ErrorView
},
jso {
path = "step"
Component = ProductionStepView
ErrorBoundary = ErrorView
},
jso {
path = "task"
Component = ProductionTaskView
ErrorBoundary = ErrorView
},
)
}
turansky
10/08/2024, 8:00 AMComponent
property - is what I use in my projects.turansky
10/08/2024, 8:01 AMturansky
10/08/2024, 8:04 AMturansky
10/08/2024, 8:06 AMHildebrandt Tobias
10/08/2024, 8:23 AMProps
depending on the route.
The alternative would be to have one component for each SubDrawer
but that would be a lot of redundant
code. I don't know how I would do this with context
.
Since the drawerItems
don't change I will try the memoization approach. Thank you.Hildebrandt Tobias
10/08/2024, 8:30 AMfun productionRoutes() = jso<RouteObject> {
path = "production"
element = memo(SubDrawer).create { drawerItems = productionDrawerItems }
ErrorBoundary = ErrorView
children = arrayOf( ... )
}
turansky
10/08/2024, 9:07 AMval myProductionElement = useMemo {
SubDrawer.create { drawerItems = productionDrawerItems }
}
Hildebrandt Tobias
10/08/2024, 9:16 AM