Merge pull request #1400 from srph/patch-1
React Hooks: Add deps to useEffect
This commit is contained in:
commit
cb4e03077f
6
react.md
6
react.md
|
@ -365,7 +365,7 @@ function Example() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Update the document title using the browser API
|
// Update the document title using the browser API
|
||||||
document.title = `You clicked ${count} times`;
|
document.title = `You clicked ${count} times`;
|
||||||
});
|
}, [count]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -379,7 +379,7 @@ function Example() {
|
||||||
```
|
```
|
||||||
{: data-line="6,7,8,9,10"}
|
{: 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.
|
By default, React runs the effects after every render — including the first render.
|
||||||
|
|
||||||
|
@ -401,7 +401,7 @@ function FriendStatus(props) {
|
||||||
return () => {
|
return () => {
|
||||||
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
|
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
|
||||||
};
|
};
|
||||||
});
|
}, [props.friend.id]);
|
||||||
|
|
||||||
if (isOnline === null) {
|
if (isOnline === null) {
|
||||||
return 'Loading...';
|
return 'Loading...';
|
||||||
|
|
Loading…
Reference in New Issue