4 ms·
I think you've missed the point if that's your takeaway. The article's solutions actually double down on hooks, proving that they are powerful and expressive en
by phailhaus 5y ago
I think you've missed the point if that's your takeaway. The article's solutions actually double down on hooks, proving that they are powerful and expressive enough to manage complex and asynchronous state precisely because they don't couple view logic and application state. That's why a generalized hook like `usePromise` is possible in the first place. The fact that you can trivially drop in a hook to make a component start dealing with asynchronous state validates the hook paradigm for UI development.
Remember: components using hooks are pure functions! That's what makes them so effective.
- joshfee 5y agoThey are _not_ pure functions. A pure function will return the same value for the same arguments every time. This is not true of functional components using hooks as the data received from calling the hook can change over time due to side effects.
- imbnwa 5y agoA thought that occurs to me is that React Hooks are Facebook engineering's attempt at an Effect monad in JS that isn't well-typed
- kristiandupont 5y agoDan goes into the topic of algebraic effects in this excellent blogpost: https://overreacted.io/algebraic-effects-for-the-rest-of-us/ https://overreacted.io/algebraic-effects-for-the-rest-of-us/
- imbnwa 5y agoThank you for this, will take a look
- phailhaus 5y ago> A pure function will return the same value for the same arguments every time. Yes, and given the same outputs provided by props + hooks, components will return the same value. That's why you can write hooks functionally, and why we can do away with class-based functions entirely. With the exception of refs, there is no actual internal state that your component needs to deal with.
- mikojan 5y agoComponents using hooks are not pure functions. The necessity(!) to wrap each and every basic JavaScript API (useEffect v. setTimeout, useLayoutEffect v. queueMicrotask, useInterval and usePromise v. using Intervals and Promises) does not at all showcase the "expressive power" of React. It was fun while it lasted but it's time to let go. React's become JQuery
- steve_adams_86 5y agoHow would you use setTimeout to replace useEffect? useEffect works by running on each render (no dependencies) or running when rendering and dependencies changed. Where does a timeout factor in? useLayoutEffect also doesn't work based on the microtask queue - it uses React's internal scheduler, which I would imagine makes sense in the context of the library. Replicating it with queueMicrotask is probably not a trivial task.
- phailhaus 5y agoThat's like saying "ugh Python's become JQuery because XXX function is not part of the standard library." You seem to be upset that people are building more useful primitives using the hooks paradigm? React deliberately ships with only a few hooks, more or less the fundamental ones that you cannot yourself implement. They left the rest up to the community to explore, because it is very difficult to predict how a new paradigm will be used. Hooks isn't just useState and useEffect, hooks are a way of writing reactive logic. It is very impressive that the community is able to produce new tools that simplify annoying problems like managing asynchronous state with just a single function, in a way that can be more-or-less dropped into any existing component.
- mikojan 5y agoThe ReactJS community is not simplifying annoying problems. The JavaScript community did that. The ReactJS community is quite literally re(!)-implementing promises here to make them work with a purported library(!). This is insane. You shouldn't need to download useConsole from npm.
- 5y ago