当前位置:网站首页>DOM processing in ahooks
DOM processing in ahooks
2022-07-25 05:03:00 【nginx】
const createEffectWithTarget = (useEffectType: typeof useEffect | typeof useLayoutEffect) => {/*** @param effect* @param deps* @param target target should compare ref.current vs ref.current, dom vs dom, ()=>dom vs ()=>dom*/const useEffectWithTarget = (effect: EffectCallback,deps: DependencyList,target: BasicTarget| BasicTarget[],) => {const hasInitRef = useRef(false);const lastElementRef = useRef<(Element | null)[]>([]);const lastDepsRef = useRef([]);const unLoadRef = useRef();// useEffect perhaps useLayoutEffectuseEffectType(() => {// Handle DOM Target elementconst targets = Array.isArray(target) ? target : [target];const els = targets.map((item) => getTargetElement(item));// init run// Execute at the first initializationif (!hasInitRef.current) {hasInitRef.current = true;lastElementRef.current = els;lastDepsRef.current = deps;// Execute... In the callback effect functionunLoadRef.current = effect();return;}// Logic not executed for the first timeif (// The target element or dependency changesels.length !== lastElementRef.current.length ||!depsAreSame(els, lastElementRef.current) ||!depsAreSame(deps, lastDepsRef.current)) {// Execute the last returned resultunLoadRef.current?.();// to updatelastElementRef.current = els;lastDepsRef.current = deps;unLoadRef.current = effect();}});useUnmount(() => {// uninstallunLoadRef.current?.();// for react-refreshhasInitRef.current = false;});};return useEffectWithTarget;};
边栏推荐
- Androd releases jitpack open source project (gradle7.2)
- harbor安装
- rhcsa暑假第三天
- [live review] AI customer service "changes according to the situation", and man-machine dialogue can be easier
- The interviewer asked MySQL transactions, locks and mvcc at one go. I
- STM32 Development Notes 119: what macros are required to enable FPU?
- 很多时候都是概率
- Forwarding and sharing function of wechat applet
- Introduction to FileStream class of C #
- 绕过 Web 应用程序中的 XSS 过滤器
猜你喜欢

rhcsa暑假第三天

PyG搭建GCN实现链接预测

Completed project series Tutorials - smart campus management system
![[CTF learning] steganography set in CTF -- picture steganography](/img/32/2da78bd5866cfab9ee64dfcb1c1204.png)
[CTF learning] steganography set in CTF -- picture steganography

Docker builds MySQL master-slave replication

Now the operator wants to check the answer details of all user questions from Zhejiang University. Please take out the corresponding data

I will write some Q & A blogs recently, mainly focusing on the points that are easy to have doubts.

5年经验的大厂测试/开发程序员,怎样突破技术瓶颈?大厂通病......

1. If function of Excel

Summary of UPR optimization suggestions of unity
随机推荐
哪种网站适合物理服务器
搭建私有CA服务器
Redis的三个必知必会的问题
When image component in wechat applet is used as background picture
[analysis of GPIO register (crl/crh) configuration of STM32]
Ffmpeg download and installation
【浅析STM32之GPIO寄存器(CRL/CRH)配置 】
2、 Mysql database foundation
Market regulation
STM32 development note 117: generate IIR low-pass filter coefficients using MATLAB
How to test data in the process of data warehouse migration?
Openworm project compilation
Docker builds MySQL master-slave replication
Ora-01460: conversion request cannot be implemented or unreasonable
It we media shows off its wealth in a high profile, and is targeted by hacker organizations. It is bound to be imprisoned
[literature notes] pointmlp
教你如何定位不合理的SQL?并优化之
AUTOSAR from getting started to mastering 100 lectures (105) - protection mechanism of AUTOSAR timing for functional safety
【微信小程序】拍卖商品详情页设计与交互实现(包含倒计时、实时更新出价)
Seven suggestions for Server Protection