What are React js 18 Dogmatic Assertion ?
I realized Suspense, and the mechanism behind it, was less created because it was the most ideal API; rather, it was borne of a single dogmatic assertion which the React team held and continues to hold, that “[rendering] should be pure, meaning that it does not modify component state, it returns the same result each time it’s invoked, and it does not directly interact with the browser”. Async functions, which are really just functions which return promises, were excluded by definition. Why? Because promises are stateful and therefore “impure.”
Knowing that this was the one immovable axiom from which the React team refused to budge, each of React’s latest design decisions seemed to fall in place. The Suspense and Fiber projects were ways to get around the fact that sync functions could not suspend, and Hooks, React’s much-discussed solution for avoiding class-based components, were really just technical aerobatics to frontload code before return statements.
Correspondingly, a lot React’s pain points began to make sense as well. All of the struggles which React developers faced, like the double-rendering or tree-walking hacks used to hydrate components with async dependencies on the server, or the whole period of collective insanity when React developers thought “render props” were good APIs, could be explained by React’s original sin of requiring rendering to be modeled exclusively as pure functions. The principle leaked into the ecosystem, radiating into developer’s lives by complicating their codebases and architectures when using React.
Freed of this dogmatic assertion, I pondered for a week or so on the kind of JSX-based library you could create if components didn’t have to be sync functions. After all, JavaScript has at present four separate function syntaxes (function, async function, function *, and async function *); wouldn’t it be nice if we could use this entire palette to write components? Could there be a use-case for generator functions as well? Again, the React maintainers dismissed generators by definition, because generator functions returned generator objects, which are stateful and therefore “impure.”