useEffect(() => {
// Update the document title using the browser API
document.title = `You clicked ${count} times`;
- });
+ }, [count]);
return (
<div>
```
{: 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.
return () => {
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
};
- });
+ }, [props.friend.id]);
if (isOnline === null) {
return 'Loading...';