Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Update template.js section #54370

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,10 @@ Templates are similar to layouts in that they wrap each child layout or page. Un

There may be cases where you need those specific behaviors, and templates would be a more suitable option than layouts. For example:

- Enter/exit animations using CSS or animation libraries.
- Features that rely on `useEffect` (e.g logging page views) and `useState` (e.g a per-page feedback form).
- To change the default framework behavior. For example, Suspense Boundaries inside layouts only show the fallback the first time the Layout is loaded and not when switching pages. For templates, the fallback is shown on each navigation.

> **Recommendation:** We recommend using Layouts unless you have a specific reason to use Template.

A template can be defined by exporting a default React component from a `template.js` file. The component should accept a `children` prop which will be nested segments.
A template can be defined by exporting a default React component from a `template.js` file. The component should accept a `children` prop.

<Image
alt="template.js special file"
Expand All @@ -234,7 +231,7 @@ export default function Template({ children }) {
}
```

The rendered output of a route segment with a layout and a template will be as such:
In terms of nesting, `template.js` is rendered between a layout and its children. Here's a simplified output:

```jsx filename="Output"
<Layout>
Expand Down