0
i will like to know the diffrent between useState and useEfect in react
hi will like to know the diffrent between useState and useEfect in react
1 Answer
+ 2
Chiemerie,
useState is like saying: I want to keep track of this thing that changes, and every time it changes, show me the new version. useState holds the message that changes.
While
useEffect is like saying: After React has shown the page, I want to run some extra work (like fetching data, starting a timer, or cleaning up)
useEffect is doing something every time that message changes (or when the component first appears).
So think of it like this, useState is like a notepad đ where you write down the latest version of something (like your message).
useEffect is like a reactive assistant đ€ who says: âHey, every time you update that notepad, Iâll do something for you.â