Skip to content

Commit

Permalink
Update props core concepts doc
Browse files Browse the repository at this point in the history
  • Loading branch information
pleek91 committed Jan 23, 2025
1 parent a23bf99 commit 36a96b0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/core-concepts/component-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,50 @@ const user = createRoute({
})
```

## Parent Props

The [callback context](/core-concepts/component-props#context) includes a `parent` property which contains the name and props of the parent route. This can be useful for passing down data to child components.

```ts
const blogPost = createRoute({
name: 'blog',
path: '/blog/[blogPostId]'
}, async (route) => {
const post = await getBlockPostById(route.params.blogPostId)

return {
post
}
})

const blogPostTabs = createRoute({
parent: blogPost,
name: 'tabs',
query: '?tab=[tab]'
component: PostTabs,
}, async (route, { parent }) => {
const tab = route.query.tab
const { post } = await parent.props

return {
tab,
post
}
})
```

:::warning
Awaiting parent props will create a waterfall of async operations which can make your app feel sluggish.
:::

## Context

The router provides a second `context` argument to your props callback. The context will always include:

| Property | Description |
| ---- | ---- |
| push | Convenient way to move the user from wherever they were to a new route. |
| parent | And object containing the name and props of the parent route. |
| replace | Same as push, but with `options: { replace: true }`. |
| reject | Trigger a [rejection](/advanced-concepts/rejections) for the router to handle |

Expand Down

0 comments on commit 36a96b0

Please sign in to comment.