React’s upcoming compiler will not solve prop-drilling, but Signals do

React’s upcoming compiler will not solve prop-drilling, but Signals do

Example: an application where the state is stored at a common ancestor of two child components that render and mutate the state.?

No alt text provided for this image

We need to pass the state (and setter) down through prop-drilling. This is the same for Signals as it is for `useState()`.

No alt text provided for this image

Even if we assume that everything is memoized through React Forget Compiler, the state prop-drilling will require that all of the components in that branch re-render.

No alt text provided for this image

In contrast, Signals are independent of the render tree and can directly update the needed component.

No alt text provided for this image

The key insight is that `useState()` is tied to the component tree, but Signals are independent of the component tree.

It's hard not to be excited about signals.

Dr. Michael Flohr

Softwareentwicklung, Management, Nachhaltigkeit

1 年

I heard the conversation about Qwick and other things with you on the Syntax Podcast. Thanks a lot for this nice talk. I found this exciting after hearing about Signals also in Solid.js. It sounds so plausible and handy to me to update the state with a getter right there and only there, exactly at the point where it is used. At the same time, I'm a big React fan. I still don't quite understand: Is it basically possible to integrate signals into React, or does the architecture of the library not allow it at all?

Seyed Tabatabaei

Front-end engineer, ReactJS+ Frameworks, Accessibility Engineer, CSS/SASS/, UX/UI Developer, Software Instructor

1 年

Neat! I thought I saw at a glimpse of a useSignal hook? I’m on mobile now but I’ll try to look it up

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了