allow typescript compiler to call setState on only one react state property

前端 未结 5 2082
半阙折子戏
半阙折子戏 2020-12-13 06:17

I\'m using Typescript with React for a project. The Main component gets passed state with this interface.

interface MainState {
  todos: Todo[];
  hungry: B         


        
5条回答
  •  情话喂你
    2020-12-13 06:55

    Update state explicitly, example with the counter

    this.setState((current) => ({ ...current, counter: current.counter + 1 }))
    

提交回复
热议问题