当前位置:网站首页>Summary of common hooks
Summary of common hooks
2022-07-29 02:56:00 【A cup of clear spring】
1、useEffact
Reference resources :https://www.cnblogs.com/guanghe/p/14178482.html
2、useState
effect : Update variables , Trigger render.
const [loading, setLoading] = useState(true);
When loading Changes will trigger render.
3、useMemo
effect : solve hooks It will trigger many useless rendering problems . If useMemo(fn, arr) The second parameter matches , And its value changes , Will be executed many times , Otherwise, execute only once , If it's an empty array [],fn Only once .
give an example :
const db = useMemo(() => new Data(dbName), [dbName]);
When dbName Render only when changes occur , Otherwise, only render once , Get the same value every time .
4、useRef
effect : Save initialized constants , It will not change throughout the life cycle , And when updated current Value does not render , This is the useState Different places .
give an example :
(1) Definition :
const id = useRef({});
(2) Set up
onClick(()=>{
id.current = 'xxxxx'
})
(3) obtain
const id = chooseList.current.id
5、useCallback
effect : Avoid multiple update calls to functions . Usage and useState The usage of is basically the same , But in the end, it will return a function , Save it with a variable .
give an example :
const getUser = useCallback(() => {
return function() {
}
}, [id])
Return function getUser Will be based on id Change by change , If id Never changed ,getUser And it won't regenerate .
边栏推荐
- Interpreting AI robots' pet raising and leading fashion trends
- Jinshan cloud returns to Hong Kong for listing: Hong Kong stock rush of Chinese to B cloud manufacturers
- STP协议(生成树协议)
- FTP协议详解
- idea配置web容器与war打包
- 第九天笔记
- Source code of Jiugongge heart puzzle Applet / source code of main wechat applet with traffic
- 金山云回港上市:中国TO B云厂商的港股奔袭
- Notes on the ninth day
- Library management system
猜你喜欢

(job) C language: Simulation Implementation of ATOI and strncpy, strncat, strncmp

C language: Little Lele and Euclid

HTB-Blue

工科男生:20岁未满,平凡但不平庸

Analysis of concepts and terms in data warehouse

Analysis of Project-based Learning Creativity in steam Education

Library management system

金山云回港上市:中国TO B云厂商的港股奔袭

第七天笔记

混淆矩阵学习笔记
随机推荐
Etcd implementation of large-scale service governance application practice
Jinshan cloud returns to Hong Kong for listing: Hong Kong stock rush of Chinese to B cloud manufacturers
这个博主,qt归类比较全,有空去学习总结,记录一下。
SQL查询数据之多表(关联)查询
qt QStringList用法
idea配置web容器与war打包
解析机器人与人类情感共鸣的主观意识
Implement encapsulated public method global call in laravel framework
HTB-Blue
Polygon zkevm - Introduction to HERMEZ 2.0
多线程实现多用例文件并发读取执行+Selenium Grid4实现测试框架分布式部署
常用hooks总结
11.书写规则-伪目标
nacos名字的由来
践踏---离散化+树状数组+差分
金山云回港上市:中国TO B云厂商的港股奔袭
Weekly recommended short videos: how to make product development more effective?
Pytest environment deployment + use case execution management + use case parameterization
创客教育的起源和内涵的基本理念
STP protocol (spanning tree protocol)