Even though I have the basics but it seems I'm still struggling, I have this example
const Component = () => {
const [state, setState] = useState("");
useEffect(() => {
console.log("useEffect");
setState("Nebil");
}, [state]);
console.log("component rerender ", state);
};
export default Component;
With the above code I see this output
component rerender
useEffect
component rerender Nebil
useEffect
component rerender Nebil
I wonder why the second time useEffect
fires, it updates the state and causes a render, I thought that when the value is equal to "Nebil" and we set the state to "Nebil" since it is a string, this will not render the component. can you please explain this to me?
note: I don't use strictmode