Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问createEffectWithTarget这个函数的设计考量是什么? #2597

Closed
yiiiiiiiiiiiiiiiiii opened this issue Jul 12, 2024 · 3 comments
Closed
Labels

Comments

@yiiiiiiiiiiiiiiiiii
Copy link

根据源码,createEffectWithTarget这个函数的主要目的是将target的变化也变成副作用Hook的执行依据

我的疑问
target是从ref引用获取的,ref是传递给对应DOM节点的,一般情况下,这个引用获取的对应的DOM对象是不会变化的,那么为什么要把这个target的变化也考虑进去呢,什么应用场景下会使得这个target变化呢?

@cold72
Copy link

cold72 commented Jul 15, 2024

dom 对象在很多业务情况下都会发生改变吧?比如key值改变,条件渲染

@crazylxr
Copy link
Collaborator

DOM 发生变化很常见的哇,如楼上说的,如果你给列表里面的元素加了事件,列表发生了变化,比如删除了。

@yiiiiiiiiiiiiiiiiii
Copy link
Author

感谢回答,之前觉得ref都是固定在对应jsx节点上,所以jsx对应的DOM不会变,忽略了DOM会从新创建的问题了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants