Why does this status wait until another status updates or a quick refresh to update? - React/NextJS
P粉232793765
P粉232793765 2023-09-08 15:09:10
0
1
430

Edit: The next version is 13.3.0

I have a state calledlocalArraythat I want to update only to a specific index, so I thought of creating a time variable to modify the array and update the state with the time value, the problem is, this state is not updated until It doesn't update until another status update or a quick refresh, I don't know why this happens

Here is a minimal reproducible example:

import { useState } from 'react' function Test() { const [someState, setSomeState] = useState(""); const [localArray, setLocalArray] = useState(["","","",""]) const handleArrayChanges = ( { target: { name, value } } ) => { let newArray = localArray; newArray[Number(name)] = value; setLocalArray(newArray); } return ( 

Array state

    Popular Topics
    More>
    Popular Articles
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!