KinoOfficial / ReactCourse

0 stars 0 forks source link

hooks #7

Open KinoOfficial opened 1 year ago

KinoOfficial commented 1 year ago
image
KinoOfficial commented 1 year ago
image image

useEffect中,第二个参数加上空数组[],相当于componentDidMount

KinoOfficial commented 1 year ago
image image
KinoOfficial commented 3 weeks ago

useMemo

父组件在更新State的时候,子组件会跟着一起重新渲染,但我们有些时候不希望它渲染来增加负担,我们可以用useMemo

缓存值的时候用useMemo,缓存组件的时候用React.Memo

image
KinoOfficial commented 2 weeks ago

useCallBack

跟memo类似,useCallBack适用于缓存函数,因为重新渲染函数会导致函数也会重新生成导致子组件重新渲染。

一般要和React.Memo配合使用,因为组件缓存了函数才需要被缓存

image
KinoOfficial commented 2 weeks ago

useReducer

image
KinoOfficial commented 4 days ago

useRef

image