Passing props in dynamic route
Unanswered
Havana posted this in #help-forum
HavanaOP
Hi all.
In my app structure, i have a layout such as:
In the above, what's the most correct way to pass props to my child route?
I need to pass a whole object, more than just the ID
In my app structure, i have a layout such as:
/clients - Parent page/clients/[id] - ChildIn the above, what's the most correct way to pass props to my child route?
I need to pass a whole object, more than just the ID
4 Replies
@Havana Hi all.
In my app structure, i have a layout such as:
`/clients` - Parent page
`/clients/[id]` - Child
In the above, what's the most correct way to pass props to my child route?
I need to pass a whole object, more than just the ID
What data are you trying to pass? Generally, on the server, you fetch data from a function.
You can leverage React's cache function on the server, which runs once per request. After that, subsequent requests pull the data from the cache.
You can leverage React's cache function on the server, which runs once per request. After that, subsequent requests pull the data from the cache.
/**
* You can call this function in every place you want
* the data, it will execute only once per server
* request
*/
const getDataFromId = React.cache((id: string) => {
...
})@Santiago Santana What data are you trying to pass? Generally, on the server, you fetch data from a function.
You can leverage React's cache function on the server, which runs once per request. After that, subsequent requests pull the data from the cache.
tsx
/**
* You can call this function in every place you want
* the data, it will execute only once per server
* request
*/
const getDataFromId = React.cache((id: string) => {
...
})
HavanaOP
I’ll explore this in the morning. The day is fetched from a supabase query in the parent page, and the supplied data is a single record from that query
@Havana I’ll explore this in the morning. The day is fetched from a supabase query in the parent page, and the supplied data is a single record from that query
You can store the query in a cached function and create another cached function that calls the first function to retrieve the record
This approach requires a different mental model, as you don't pass data directly. The benefit, is that it allows for better composition