An Alternative Perspective on React-State-Containers
This article provides an alternative perspective on React-State-Containers, a new layer that can run at the same time as existing features like useState, react-query, and CSS-in-JS. It explains how this paradigm works and why it is important.
дэн
the results are always perfect
-
fwiw i expected the article to be clickbait (and the title is) but it’s actually pretty balanced. imo it gets a few things wrong so i’ll provide an alternative perspective (tiny thread) https://t.co/UkSU7zdkxm
— дэн (@dan_abramov) June 7, 2023 -
the framing of “existing features like useState / react-query / CSS-in-JS don’t work” is misleading at best.
— дэн (@dan_abramov) June 7, 2023
to understand why, consider that here is the React you already know… pic.twitter.com/sg7VWiYi5M -
… in the RSC paradigm, all of these things keep working! we are not *replacing* that layer — we are adding a *new* layer that can run at the build or request time. that’s Server Components. the only thing they can do is pass data to the “React you already know”… pic.twitter.com/KK5bRtVKaG
— дэн (@dan_abramov) June 7, 2023 -
… to disambiguate the two layers, we’ve renamed the old layer to “Client” React. all of the features and libraries you used before keep working in that part of the world — we literally haven’t touched it. we just gave it a different name. pic.twitter.com/myUUu0HwDj
— дэн (@dan_abramov) June 7, 2023 -
this is why “existing features don’t work” is misleading. they don’t work in the *new* layer but they work exactly like before in the existing one. you can use as little of the new layer as you want.
— дэн (@dan_abramov) June 7, 2023
here’s a linkable explanation: https://t.co/y2kJ6Sotyq -
React Server is an attempt to standardize the best parts of existing solutions to the same problems (Remix loaders, Astro templates, GraphQL fragments) in a way that feels native to the React paradigm. we want you to be able to share React components with server logic across fw.
— дэн (@dan_abramov) June 7, 2023 -
it *feels* like existing features are broken because Server Components are a new “entry point” into your code, like a “plain React” version of Remix loaders / Gatsby queries / Astro templates / getServerSideProps / getStaticProps. then “use client” drops you down to Client world.
— дэн (@dan_abramov) June 7, 2023 -
a few other things that seem off:
— дэн (@dan_abramov) June 7, 2023
1. the default for running RSC in Next is build-time, not runtime. seems like an odd default if this is all a conspiracy to sell more servers. :)
2. the RSC work was driven by the React team — since 2018. more on that at the end of this panel: https://t.co/SBmuK2eLDn -
hope that helps!
— дэн (@dan_abramov) June 7, 2023