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

coomitRoot阶段layout阶段阐述存疑 #107

Open
daxiazilong opened this issue Jan 21, 2022 · 0 comments
Open

coomitRoot阶段layout阶段阐述存疑 #107

daxiazilong opened this issue Jan 21, 2022 · 0 comments

Comments

@daxiazilong
Copy link

beforeMutation阶段
就讲过,before mutation阶段在scheduleCallback中调度flushPassiveEffects

而在layout阶段

对于FunctionComponent及相关类型,他会调用useLayoutEffect hook的回调函数,调度useEffect的销毁与回调函数

光从以上两段论述中,是不是可以说 useEffect的相关回调在beforeMutation和layout两个阶段都被调用了啊

17.0.2源码我大概看了下 对应位置的代码似乎变成了:

case FunctionComponent:
    case ForwardRef:
    case SimpleMemoComponent:
    case Block:
      {
        // At this point layout effects have already been destroyed (during mutation phase).
        // This is done to prevent sibling component effects from interfering with each other,
        // e.g. a destroy function in one component should never override a ref set
        // by a create function in another component during the same commit.
        {
          commitHookEffectListMount(Layout | HasEffect, finishedWork);
        }

        schedulePassiveEffects(finishedWork);
        return;
      }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant