1function SyncedInput({ externalValue }) {
2 const [value, setValue] = useState('');
3
4 useEffect(() => {
5 setValue(externalValue);
6 });
7 // Missing dependency array
8
9 return <input value={value} onChange={e => setValue(e.target.value)} />;
10}
no lines flagged
#058PracticeHard25 min · 200 XP
Infinite Loop in useEffect with setState
This component triggers an infinite render loop because a useEffect both reads and writes the same state without a condition.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.