Skip to content

Commit

Permalink
Merge pull request rstacruz#1400 from srph/patch-1
Browse files Browse the repository at this point in the history
React Hooks: Add deps to useEffect
  • Loading branch information
rstacruz authored Apr 3, 2020
2 parents 447de94 + a652d42 commit cb4e030
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions react.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ function Example() {
useEffect(() => {
// Update the document title using the browser API
document.title = `You clicked ${count} times`;
});
}, [count]);

return (
<div>
Expand All @@ -379,7 +379,7 @@ function Example() {
```
{: data-line="6,7,8,9,10"}

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

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

Expand All @@ -401,7 +401,7 @@ function FriendStatus(props) {
return () => {
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
};
});
}, [props.friend.id]);

if (isOnline === null) {
return 'Loading...';
Expand Down

0 comments on commit cb4e030

Please sign in to comment.