React Hook: useEffect

React framework:

Sometimes you want to perform some additional operations after the page is updated (that is, to update the DOM), such as requesting network data, manually changing the DOM or diary records.

Use different methods in the class component and function component, as follows

1: class component

In React class components, the render method itself should not perform side-effect operations, but we sometimes want to perform some operations after react updates the dom, and put the side effects in mponentDidMount () and componentDidUpdate ()

2: function component

By using this useEffect, the React component is notified of what operations need to be performed after rendering. The following example. UseEffect will run after the first render and after each update. After the page update, that is, the dom rendering is completed, through the get () method, get ({pageNum, pageSize}), request the remote data to render the page. When the entire component is loaded, some additional things must be triggered is Effect.

In this case, the component is only loaded on the page, but it also requires dynamic data and other actions. These actions are not what the component has to do, but the component still needs to trigger these actions, which is useEffect.

Of course, useEffect will only be executed after the entire component is completed

 

 

 

Guess you like

Origin www.cnblogs.com/yt0817/p/12682080.html