Is the constructor still needed in React with autobinding and property initializers

后端 未结 3 1892
悲&欢浪女
悲&欢浪女 2021-02-05 17:39

I am refactoring an es6 class based React component that uses the normal constructor, and then binds methods, and defines state/attributes within that constructor. Something lik

3条回答
  •  别那么骄傲
    2021-02-05 18:18

    You don't need an explicitly defined constructor unless you need to reference the props in your initial state object.

提交回复
热议问题