Hacker News new | ask | show | jobs
by v3ss0n 1062 days ago
This is wrong in so many levels. You need to learn useState,useEffects in react.

You only need to learn how to put {varName} in svelte.

2 comments

useState and useEffect are quite simple small elegant API. It does not mean it's very easy to use for newbie. Maybe like Lisp?
Oh sure, useState and useEffect are very simple. Your app built upon them, on the other hand…
You don't need to learn useEffect until you need to plug arbitrary js libs and components into react. That's the intended use of useEffect. Using it for anything else is usually a bad idea.
How can you "fetch something when your state change ?". It's the main use case for useEffect.
You can just trigger fetch in the function that does the state change.
Agreed, this is the correct approach. Overusing effects makes control flow difficult to understand and has many unintended consequences. The misuse of effects is so widespread the React team had to address it with Strict mode in React 18.