Skip to content Skip to sidebar Skip to footer

Wait For State To Update Using UseState Hook And Then Run Code Inside A Funciton

const startLive = () => { // connect to websocket only on start button setliveChartState({ ...liveChartState, liveActive: !liveChartState.liveActive,

Solution 1:

The new set state value will only be available on the next render. I would suggest using useeffect. Or you could use useReducer instead. That would work too


Post a Comment for "Wait For State To Update Using UseState Hook And Then Run Code Inside A Funciton"