Live data from Hacker News

Show HN: Tired of logic in useEffect, I built a class-based React state manager

thales.me

21–30 of 57 posts

Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager

#22

Javascript and classes go together like toothpaste and orange juice. All good JS programmers I know essentially pretend that classes don't exist in the language (or if they use them, they only do so rarely, for very niche cases). JS does not have classical OOP built in! It has Brandon Eich's prototypal inheritance system (which has some key differences), along with a 2015 addition to the language to pretend it has OO…

Potato potato. Js classes are just closure sugar. So what?

Syntax makes sense and improves readability in business logic. Readability is good

Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager

#23

Javascript and classes go together like toothpaste and orange juice. All good JS programmers I know essentially pretend that classes don't exist in the language (or if they use them, they only do so rarely, for very niche cases). JS does not have classical OOP built in! It has Brandon Eich's prototypal inheritance system (which has some key differences), along with a 2015 addition to the language to pretend it has OO…

Counterpoint: classes are a great way to bundle state and logic - which is exactly what UI components are - and components models should use classes more , not less. React's "functional" components are simply poor approximations of classes. Instead of easy to read and reason about class fields, you put state in useState() function classes that are effectively named by their appearance order in source and who's curren…

They're modeling reactivity, not classes. It's a well established pattern in functional programming

The one time setup mixed with repeated render calls is odd, but it's a design decision they made. It reduces boiler plate, though I don't necessarily agree with it because it is a leaky abstraction

Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager

#24

Javascript and classes go together like toothpaste and orange juice. All good JS programmers I know essentially pretend that classes don't exist in the language (or if they use them, they only do so rarely, for very niche cases). JS does not have classical OOP built in! It has Brandon Eich's prototypal inheritance system (which has some key differences), along with a 2015 addition to the language to pretend it has OO…

Encapsulation, inheritance and polymorphism all work fine with JavaScript classes. OOP works just fine. What doesn't work in JavaScript is functional programming.

I don’t see how? You can do all sorts of FP in js and it even has some of it in its built in APIs. .then comes from FP

Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager

#25

Javascript and classes go together like toothpaste and orange juice. All good JS programmers I know essentially pretend that classes don't exist in the language (or if they use them, they only do so rarely, for very niche cases). JS does not have classical OOP built in! It has Brandon Eich's prototypal inheritance system (which has some key differences), along with a 2015 addition to the language to pretend it has OO…

> Javascript and classes go together like toothpaste and orange juice.

Even HN has been taken over by shills from Big Mint.

Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager

#26

Earlier quoted context omitted.

Encapsulation, inheritance and polymorphism all work fine with JavaScript classes. OOP works just fine. What doesn't work in JavaScript is functional programming.

I don’t see how? You can do all sorts of FP in js and it even has some of it in its built in APIs. .then comes from FP

Yes, but promises are (unfortunately) _not_ monads!

https://rybicki.io/blog/2023/12/23/promises-arent-monads.htm...

Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager

#27
You can use React in an MVC framework, with React used to implement the 'V' in MVC. You can use class components, and the code becomes extremely simple. Business logic is moved to 'M' layer (models) and the 'C' layer (controllers) coordinates everything. No hooks or other messy stuff needed.

In fact, React was originally designed to be used this way (as the V in MVC)!

See https://github.com/Rajeev-K/mvc-router

Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager

#28

Javascript and classes go together like toothpaste and orange juice. All good JS programmers I know essentially pretend that classes don't exist in the language (or if they use them, they only do so rarely, for very niche cases). JS does not have classical OOP built in! It has Brandon Eich's prototypal inheritance system (which has some key differences), along with a 2015 addition to the language to pretend it has OO…

I went through the code, and it is roughly equivalent to doing it without classes. The nesting level in the example isn't deep - everything seems to be beneath a SnapStore or a SnapFormStore, without inheriting from user defined classes. I think the use of classes is fine, and the way that it's introduced in the blog post is good, it says "plain TypeScript classes". It is used as a means for ergonomically writing and understanding the code more than it is for setting up invariants or complex polymorphism.

Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager

#29
post #6

Earlier quoted context omitted.

For clarity, what do you call "classical OOP"? (disclaimer: FP all the way, regardless)

Essentially `new Foo()`, where `Foo` can be a subclass of `Bar` that inherits properties in the same way we all learned in our Java (or whatever actual OOP) language. JavaScript gives you a class syntax that lets you make classes and extend them from each other, and for the most part they will work the same way as a class from a language like Java ... but some things won't. You can either become an expert on prototyp…

Don’t most OO languages have similar differences? My understanding is that even Java is quite different from, say, Smalltalk (which arguably is “more OG”).

Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager

#30
post #16

The problems OP tries to address are unfortunately a deep design flaw in mainstream frameworks like React and Vue. This is due to 2 properties they have: 1. They marry view hierarchy to state hierarchy 2. They make it very ergonomic to put state in components I've been through this endless times. There are significant ways to reduce this friction, but in the end there's a tight ceiling. This is why this kind of work…

Is this because Elm forces you to separate the model computations from the view computations, which then lets you compose the model shape in one place and the view shape in the other, or some other property of the framework that I'm not aware of?
Post reply on HN