current position:Home>Details of Vue to react useeffect

Details of Vue to react useeffect

2022-04-29 04:26:02baoleilei6

useEffect It is used to process effect, Usually used to request data , Event handling , Subscription and other related operations .

useEffect Second parameter of :

1. When useEffect When there is no second parameter

You can see from this example useEffect When there is no second parameter, it keeps calling

2. When useEffect When the second parameter is an empty array

From this example, we can see that useEffect After one call, you don't call

3. When useEffect When the second parameter is a variable

From this example, we can see that useEffect In every time count Called when a change occurs

useEffect Use :

As can be seen from the above example, use useEffect And class component Differences when using lifecycle functions , Use useEffect Will each time count The changed data are printed out , While using componentDidUpdate Printed the last data many times , because class component Inside state With render It's changing , and useEffect Everything inside is every time render independent .

useEffect eliminate :

useEffect adopt return Do some cleanup .

For example, examples in official documents , When props.friend.id When something changes , It can be cleared



author : Yi Xiaohan
link :https://www.jianshu.com/p/2115c3253e98
source : Simple books
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .

copyright notice
author[baoleilei6],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/117/202204270552176581.html

Random recommended