4 ms·
> React is a lot more stable than I think you're giving it credit for. A lot of the HN zeitgegist would have you believe React is the opposite, sadly.
by lloydatkinson 1y ago
> React is a lot more stable than I think you're giving it credit for.
A lot of the HN zeitgegist would have you believe React is the opposite, sadly.
- CaptainOfCoit 1y agoThe React ecosystem moves really quickly, and likes to re-invent wheels. But React core APIs remain relatively stable, I've been using React the same way for many years at this point, and you can ignore the parts you don't like, like I'm ignoring hooks and haven't found a single use case where I needed them.
- adithyassekhar 1y agoCould you please tell me how are you avoiding hooks? You're not using useState or useEffects?
- CaptainOfCoit 1y agoI mainly use React via Reagent in ClojureScript, and literally have no use cases where I need to use useState/useEffects for anything. Turning it around, what exactly are you unable to do without useState/useEffects?
- adithyassekhar 1y agoWhen I want to memoize something slightly complex, for simplicity's sake let's say sorting an array of objects based on one of it's keys. I can put that in a useMemo and it won't sort it again when the page eventually rerenders for some reason. Usually that array is mapped elsewhere and those child components might also re render if the array is recalculated. useEffects are when I need to call something outside of react, or when the page gets mounted or I need to call a function when something changes. I'm still fairly new to this, the above examples may scream bad architecture to those more experienced, all criticisms welcome :)
- Octoth0rpe 1y ago> all criticisms welcome :) No criticism really. Your useMemo example is the right use. Your useEffect use is fine, but for things like api calls (which 'call something outside of react' may refer to), you're often better leaning on something like react-query, which is of course built on top of useEffect. So still the right tool, but let others handle many of the sharp edges around that problem.
- adithyassekhar 1y agoThanks. I've started with rtk and saga hence the useEffect. I've since moved to rtk query.
- Our_Benefactors 1y ago> I can put that in a useMemo and it won't sort it again when the page eventually rerenders for some reason useMemo dependency smell. This is almost always because your dependencies are wrong. This can often happen if you put a dependency as [object] instead of [object.field] due to how JavaScript maps objects to memory.
- skydhash 1y agouseMemo is quite nice when you're doing data transformation against some API call or other big data structure.
- Our_Benefactors 1y agoYes, it is, but you still have to declare your dependencies correctly.
- adithyassekhar 1y agoNever thought of it that way. What if it's an array though, how will I put it as a dependency?
- Octoth0rpe 1y agoclass components (which do not use hooks) are still supported by React with no scheduled deprecation AFAIK.
- homebrewer 1y agoOne of the projects I sometimes work on uses class components + mobx; it runs circles around hooks in speed/debuggability/convenience IMHO.
- Tubelord 1y agoI learned React before hooks. Came from a mostly forgotten framework called ExtJS that used base JavaScript classes, so it was an easy transition. Class based React is great. My old projects are cleanly structured, but harder to change. Class based React also lacks the composability you get with hooks.