ReactJS - prevState in the new useState React hook?

前端 未结 4 858
南方客
南方客 2021-01-31 17:45

I really like the new React hooks and I\'m using them frequently for a project I\'m working on. I\'m coming across a situation where I want to use the prevState in the

4条回答
  •  故里飘歌
    2021-01-31 18:16

    You have already the previous state in the destructed variable: someState

    so you can do:

    const [ someState, setSomeState ] = useState( new Map() )
    setSomeState( someState.set( key, value ) )
    

提交回复
热议问题