Next.js Discord

Discord Forum

Object update in useState is not working as expected

Unanswered
XotEmBotZ posted this in #help-forum
Open in Discord
Javascript Scares
    const stopDetect = () => {
        const d = false
        console.log("In toggel", d)
        if (d) cameraObj.start()
        if (!d) cameraObj.stop()
        setDetectStart(d)
        notifications.show({
            message: `Data regarding ${label} is captured`,
            withCloseButton: true,
            title: "Data captured",
            color: "green",

        })
        results[label] = tempData
        console.log(label, results, results[label])
        setResults(results)
        setTempData([])
        setLabel("")
    }

Even after the change in label the insertion dosent take place in right place.
1st label-Control
2nd label-Fedora Laptop

But the fedora laptop length is 0

the console.log statement result
Fedora Laptop {control: Array(257), Fedora Laptop: Array(0)} []

What am I doing wrong??

0 Replies