Little tip, when you update a state based on its previous value prefer using the function instead of what you're doing with the items list for example. Like : [someNumber, setNumber] = useState(0); setNumber((prev) => prev+1) This way you're sure to always have the ACTUAL previous value. :)
In imperative way you explicitly write the shortest possible code, that will just work, and you totally understand it. In "declarative" way you write the code you hope will work, using lots and lots of code that someone else wrote, and you, more often than not, don't really understand how it work.
This article from the React docs might also help clear this up: react.dev/learn/reacting-to-input-with-state#how-declarative-ui-compares-to-imperative
Who on earth writes react the same way as imperative code
Little tip, when you update a state based on its previous value prefer using the function instead of what you're doing with the items list for example.
Like :
[someNumber, setNumber] = useState(0);
setNumber((prev) => prev+1)
This way you're sure to always have the ACTUAL previous value. :)
In imperative way you explicitly write the shortest possible code, that will just work, and you totally understand it. In "declarative" way you write the code you hope will work, using lots and lots of code that someone else wrote, and you, more often than not, don't really understand how it work.
I don't think that's how it works....
@perigord6281 How you think it does? By the miracle? Browsers understand only that f*cking vanilla js - nothing more.
@@TheHellishFrog not trying to be condescending but I have literally no idea what you're talking about
@perigord6281 Could I suggest - first get an idea based on solid understanding of the subject at hand - and only then - talk.
@@TheHellishFrog really just seems like you're placing declarative code as some sort of Boogeyman without any proper elaboration, but ok