4 ms·
The difference is in how the state is handled. In Clojure, it is contained in an atom, which is a well documented language primitive which can change value in c
by jmiskovic 7y ago
The difference is in how the state is handled. In Clojure, it is contained in an atom, which is a well documented language primitive which can change value in controlled manner. It's not some magic construct hidden behind innocently looking JS function useState().
- dhucerbin 7y agoTo be fair, reagent uses it's own implementation that satisfy atom protocol. And it uses some funky magic with keeping derefs and triggering rerenders. In principle, as atom is idiomatic Clojure, setState is idiomatic javascript. ratoms and hooks both add some sugar to it.
- pgt 7y ago`setState(...)` is not idiomatic in JavaScript.
- dhucerbin 7y agoI'm not sure how far back you want to go, but `this.set` is used in most frontend frameworks, starting around knockout and backbone. You had object which managed state for you (then it was model, today it is component) and it had some setter method.
- ArchReaper 7y agoReact is open source, you can view the source for this "magic construct" so I don't see any validity to your argument. useState returns 2 variables - a getter and a setter, where the getter is just a variable and not even a function to call. How is that equatable to some hidden construct? How is Clojure superior to that?