2 ms·
IMO hooks are a DSL implemented in js. React went from class to function components to hooks as preferred practices. In the process, the previous was not cleane
by mejutoco 5y ago
IMO hooks are a DSL implemented in js. React went from class to function components to hooks as preferred practices. In the process, the previous was not cleaned up (until very recently, maybe still, you needed a class component to catch exceptions in a component). It feels like change for changes sake, were only new features are explored without making the whole consistent.
I like React a lot. A simple conceptual model, like elm or other frameworks mentioned here, would work better that this constant change.
- dragonwriter 5y ago> React went from class to function components to hooks as preferred practices Hooks work with function components, and are how component state and the equivalent of lifecycle methods are implemented in function components. For a while with function components, higher-order components were a common complementary approach to hooks, which have themselves largely had their function subsumed by hooks, so you could maybe describe the trend as: class components => function components + hooks + HOC => function components + hooks.
- mejutoco 5y agoThat sounds right. In my own anecdotal experience I see a much bigger push to use hooks for everything, where before only useEffect and a few others would be expected. I wish old methods would be deprecated and all features made available in function components.
- kazinator 5y agoWe know from Lisp that, for instance, you can write a while loop like this. (defmacro while (condition &rest body) `(let ((cond-fun (lambda () ,condition)) (body-fun (lambda () ,@body)) (while-macro-run-time-function cond-fun body-fun))) Then we have a run-time support function: (defun while-macro-run-time-function (cond-function body-function) (loop while (funcall cond-function) do (funcall body-function))) Closures allow macros to parcel off expressions or bodies of expressions into functions, so that control structures can then be made "remote": put into a function. This has the benefit of keeping expansions small. Another benefit is that since the core logic is in the run-time function(s), those can be updated to fix something without having to recompile the macro invocations. Somehow, the sky doesn't fall in Lisp land; we don't need articles like, OMG I learned about this in 2018 and it's so dangerous.
- mejutoco 5y agoI think probably you intended to reply to some other user, unless I am missing sth. I see a difference with hooks, where you need a linter to verify that you used them as intended: they must start with useSomething and be called in the top level. As opposed to use native language features.