mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-04-08 11:56:41 +00:00
Add details to useEffect and class components
This commit is contained in:
parent
1537a849e8
commit
dea6850e85
1 changed files with 8 additions and 5 deletions
|
@ -114,6 +114,8 @@ class Button extends React.Component {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {count: 0};
|
this.state = {count: 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {} // called on successful component mount
|
||||||
|
|
||||||
handleClick = () => {
|
handleClick = () => {
|
||||||
this.setState({ count: this.state.count + 1 });
|
this.setState({ count: this.state.count + 1 });
|
||||||
|
@ -223,14 +225,15 @@ const [state, setState] = useState(default);
|
||||||
|
|
||||||
### `useEffect`
|
### `useEffect`
|
||||||
|
|
||||||
Hook used to trigger an action on each reder of the component.
|
Hook used to trigger an action on each reder of the component or when one of the watched items changes.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
useEffect(() =>
|
|
||||||
// introduce side effect of the render
|
|
||||||
|
|
||||||
return () => {/* clean up side effect */}
|
useEffect(() => {
|
||||||
);
|
// "side effects" operations
|
||||||
|
|
||||||
|
return () => {/* clean up side effect */} // optional
|
||||||
|
}, [/* list of watched items, empty triggers once */]);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Custom Hooks
|
### Custom Hooks
|
||||||
|
|
Loading…
Add table
Reference in a new issue