top | item 40678234

(no title)

akritrime | 1 year ago

You could already use functional components before. The main issue with React now is all these hooks and effects.

discuss

order

crooked-v|1 year ago

The whole point of hooks is to substantially simplify "effects stuff", as compared to the total uncomposability of class components.

While the specific implementation of hooks has its bugbears, I think it's pretty telling that nobody else is using class components either, even in projects with fundamentally different engines like Svelte.

azangru|1 year ago

> as compared to the total uncomposability of class components

How do you mean? React components were composable from the get-go; this is practically the definition of a component: you take a piece of ui, you encapsulate it in a component, and then you can compose it with other components into more complex UIs.

Class components were reacting to component's life cycle as opposed to hooks that react to data changes; but there was nothing stopping you from extracting reusable pieces of logic into standalone functions and using them in lifecycle methods.

I thought the whole point of hooks was to support the React fiber architecture, because closures are immutable as opposed to class fields.

cageface|1 year ago

Hooks make it easy to compose logic and effects. The actual implementation has some serious warts but the fundamental idea is great.

The React compiler looks like it will eliminate a lot of the error prone manual dependency tracking that usually trips people up with hooks.