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

Why does set state always start the work from root again #53

Open
hskrishandi opened this issue Sep 22, 2023 · 0 comments
Open

Why does set state always start the work from root again #53

hskrishandi opened this issue Sep 22, 2023 · 0 comments

Comments

@hskrishandi
Copy link

Awesome blog post! It has been the best guide that I've ever read and really helped me understand the internals of React Fiber architecture.

One thing that I notice is that inside the useState, the setState will always set nextUnitOfWork = wipRoot, which means Didact will reconcile from the root. And inside updateFunctionComponent, the function component will always call fiber.type(fiber.props) which will cause the component re-render. But I believe this is not the case in React?

For example, we have this structure: https://playcode.io/1603467

<Parent>
  <Children />
</Parent>

const Parent = ({ children }) => {
  console.log('parent re-render')

  return <div>{children}</div>
}

const Children = (props) => {
  const [state, setState] = useState(0);
  console.log('child re-render')

  return <button onClick={() => setState(state+1)}>Click</button>
}

In actual React, when the <Children> button is clicked and setState is invoked, the <Parent> component will not-rerender. It is reflected by the parent console.log, which doesn't run again.

So my question is, how does Didact differ from React in this case? Which React's feature is not implemented in Didact?
Thanks

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