Show HN: Tired of logic in useEffect, I built a class-based React state manager
21–30 of 57 posts
Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager
#22Javascript 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…
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
#23Javascript 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…
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
#24Javascript 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.
Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager
#25Javascript 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…
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
#26Earlier 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
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
#27In fact, React was originally designed to be used this way (as the V in MVC)!
Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager
#28Javascript 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…
Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager
#29Earlier 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…
Re: Show HN: Tired of logic in useEffect, I built a class-based React state manager
#30The 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…