News for hackers. Stuff that matters.
Re:Making SetInterval Declarative with React Hooks by mambodog on Monday February 04, 2019 @02:44AM (#19074634)
How do you compose two base classes into a subclass? That's basically what hooks allows. You can use two different, unrelated custom hooks in one component, and a different combination in another component, without having to bundle them into base classes.
Re:Making SetInterval Declarative with React Hooks by sowhatquestion on Monday February 04, 2019 @03:24AM (#19074760)
> How do you compose two base classes into a subclass?

In most other OOP languages besides JS, the obvious answer would be to use traits.

Re:Making SetInterval Declarative with React Hooks by mambodog on Monday February 04, 2019 @11:49AM (#19077839)
Traits are okay: React 'Mixins' which I mentioned in my parent post are basically traits but at the framework level, which allows them to be smart about composing/merging the use of framework functionality normally accessed by overriding superclass methods (eg. componentDidUpdate). Traits still have the composability issues I mentioned for React Mixins: how do you avoid collisions between the namespaces of different traits while still allowing some to compose others?
Re:Making SetInterval Declarative with React Hooks by mst on Monday February 04, 2019 @04:09AM (#19074934)
Hence why I've been playing around with class decorators and friends to try and figure out a nice way to do method modifiers, traits, etc.

But I got sidetracked with "but howtf do I make typescript understand the resulting signatures" and then got nerd sniped by something else.

Hopefully eventually I'll get back to it.

Re:Making SetInterval Declarative with React Hooks by danabramov on Monday February 04, 2019 @05:16AM (#19075168)
If you want to understand what Hooks are for, I wrote this piece:

https://medium.com/@dan_abramov/making-sense-of-react-hooks-...

I hope you find it helpful!

Hooks aren't _quite_ like traits or mixins or anything else. You can apply the same Hook multiple times and pass values between them. That's what makes them powerful.

Look at my last demo.

https://overreacted.io/making-setinterval-declarative-with-r...

Re:Making SetInterval Declarative with React Hooks by mst on Wednesday February 06, 2019 @05:55AM (#19094178)
Yeah, definitely a different beast. I've done things with what's basically dynamic scope trickery before now, though it didn't look exactly like hooks.

I still want traits because I've got very fond of doing class-with-read-only-members type stuff and being able to compose functionality together works really nicely in that regard

(nonetheless, I very much appreciate your efforts on elucidating hooks - I think most of the reason I'm replying this confidently is as combination of your articles and the reference docs :)

Re:Making SetInterval Declarative with React Hooks by goatlover on Monday February 04, 2019 @07:35AM (#19075773)
Maybe React hooks are a bit different, but Drupal was heavily hook based, and then starting going away from that in favor of Symfony components in recent years, which are class based and utilize inheritance. Also, UI has typically been considered one of the areas where OOP is well suited for, from Smalltalk to the Web DOM.
Re:Making SetInterval Declarative with React Hooks by lj3 on Monday February 04, 2019 @08:29AM (#19076163)
> UI has typically been considered one of the areas where OOP is well suited for

Without any evidence to support it. It's one of those phrases that gets repeated without critical thought.