Skip to content

Commit a652d42

Browse files
authored
Add deps to useEffect
1 parent 447de94 commit a652d42

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

react.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ function Example() {
365365
useEffect(() => {
366366
// Update the document title using the browser API
367367
document.title = `You clicked ${count} times`;
368-
});
368+
}, [count]);
369369

370370
return (
371371
<div>
@@ -379,7 +379,7 @@ function Example() {
379379
```
380380
{: data-line="6,7,8,9,10"}
381381

382-
If you’re familiar with React class lifecycle methods, you can think of `useEffect` Hook as `componentDidMount`, `componentDidUpdate`, and `componentWillUnmount` combined.
382+
If you’re familiar with React class lifecycle methods, you can think of `useEffect` Hook as `componentDidMount`, `componentDidUpdate`, and `componentWillUnmount` combined.
383383

384384
By default, React runs the effects after every render — including the first render.
385385

@@ -401,7 +401,7 @@ function FriendStatus(props) {
401401
return () => {
402402
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
403403
};
404-
});
404+
}, [props.friend.id]);
405405

406406
if (isOnline === null) {
407407
return 'Loading...';

0 commit comments

Comments
 (0)