当前位置:网站首页>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 .
边栏推荐
- 混淆矩阵学习笔记
- Cloud development pocket toolbox wechat applet source code
- 【OpenCV】使用OpenCV调用手机摄像头
- Restfulapi - C - add header username and password authentication
- Add a row to a specific location in the dataframe
- MySQL compound query (important)
- golang 协程的实现原理
- PHP process communication series (I) named pipes
- 第六天笔记
- 算法---粉刷房子(Kotlin)
猜你喜欢

Jinshan cloud returns to Hong Kong for listing: Hong Kong stock rush of Chinese to B cloud manufacturers

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

Some new ideas about time complexity

Polygon zkevm - Introduction to HERMEZ 2.0

第五天实验

架构师进阶,微服务设计与治理的 16 条常用原则

区区区间---线段树lazy标记板子题

Thirty years of MPEG audio coding

DHCP protocol detailed analysis

DataGrip 如何导出和恢复整个数据库数据,使用单个 SQL 文件
随机推荐
工科男生:20岁未满,平凡但不平庸
Implement encapsulated public method global call in laravel framework
第七天笔记
codeforces每日5题(均1500)-第二十五天
Summary of classic problems in Flink production environment
并发模式之异步回调Future模式
Analysis of concepts and terms in data warehouse
Add a row to a specific location in the dataframe
Flink内核源码(七)Flink SQL提交流程
owt-server源码剖析(三)--video模块分析之Mixer In
FTP协议详解
Confusion matrix learning notes
Cloud development pocket toolbox wechat applet source code
UE4.25 Slate源码解读
Restfulapi - C - add header username and password authentication
Mysql复合查询(重要)
Analysis of Project-based Learning Creativity in steam Education
The origin of Nacos' name
Pgzero aircraft war
nacos名字的由来