Question:
Answer:
You are unconditionally enqueuing the state update. The component is stuck render looping.Use a
useEffect
or some other conditional way (i.e. onClick
callback, etc) to enqueue the state update.Example:
export default function Box() {
const [count, setCount] = useState('hello');
useEffect(() => {
setCount("welcome");
}, []);
return (
);
}
If you have better answer, please add a comment about this, thank you!