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

Add additional fix in hydration error document #40675

Merged
merged 5 commits into from Sep 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions errors/react-hydration-error.md
Expand Up @@ -36,6 +36,30 @@ function MyComponent() {
return <h1 className={`title ${color}`}>Hello World!</h1>
}
```
Another example:
NextJS is not comfortable having a p tag wrapping your divs, sections etc so it will yell "Hydration failed because the initial UI does not match what was rendered on the server".
abdennor marked this conversation as resolved.
Show resolved Hide resolved
```jsx
export const IncorrectComponent = ()=>{
return(
<p>
<div>This is not correct and should never be done because the p tag has been abused</div>
<Image src='/vercel.svg' alt='' width='30' height='30'/>
</p>
)
}
```
How to fix it:
```jsx
export const CorrectComponent = ()=>{
return(
<div>
<div>This is correct and should work because a div is really good for this task.</div>
<Image src='/vercel.svg' alt='' width='30' height='30'/>
</div>
)
}
```
Credits : stackoverflow user : @Motsi url https://stackoverflow.com/a/71870995

Common causes with css-in-js libraries:

Expand Down