skip to Main Content

Reactjs – Syncing States between parent and child

const [counter, setCounter] = useState(0); useEffect(() => { const intervalId = setInterval(() => { setCounter((prevCounter) => prevCounter + 1); }, 1000); return () => clearInterval(intervalId); }, []); const handleOpenModal = () => { showModal({ title: "Confirmation", key: `modal-${counter}-${Date.now()}`, content: ()…

VIEW QUESTION

Javascript – State update creates infinite loop

Why does assigning the setTimeSlotsList(fetchAPI(day)) create an infinite loop? The code flow seems to be working when I just console.log(fetchAPI(day)) for testing. const [timeSlotsList, setTimeSlotsList] = useState([]) function FormValues () { const { values } = useFormikContext(); const day =…

VIEW QUESTION
Back To Top
Search