You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/learn/render-and-commit.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,6 +194,48 @@ export default function App() {
194
194
</Sandpack>
195
195
196
196
This works because during this last step, React only updates the content of `<h1>` with the new `time`. It sees that the `<input>` appears in the JSX in the same place as last time, so React doesn't touch the `<input>`—or its `value`!
197
+
## Debugging Hydration Mismatches
198
+
199
+
Hydration mismatches can occur when the HTML rendered on the server differs from what React renders on the client.
200
+
201
+
### Common causes
202
+
203
+
- Non-deterministic values such as:
204
+
-`Math.random()`
205
+
-`Date.now()`
206
+
- Using browser-only APIs like `window` or `document` during render
207
+
- Differences between server and client environments
208
+
- Asynchronous or inconsistent data
209
+
210
+
### Example
211
+
212
+
```jsx
213
+
functionApp() {
214
+
return<div>{Math.random()}</div>;
215
+
}
216
+
```
217
+
218
+
### How to fix
219
+
- Move non-deterministic logic into `useEffect`
220
+
- Ensure consistent data between server and client
After rendering is done and React updated the DOM, the browser will repaint the screen. Although this process is known as "browser rendering", we'll refer to it as "painting" to avoid confusion throughout the docs.
0 commit comments