React.createClass vs. ES6 arrow function

前端 未结 2 656
礼貌的吻别
礼貌的吻别 2020-11-29 06:44

I\'m new to React and trying to get a handle on syntax.

I\'m developing in a React 15 environment (using the react-starterify template) and have been using the synt

2条回答
  •  粉色の甜心
    2020-11-29 07:12

    To be added, from react 15.5.0, React.createClass will be deprecated. They recommend you to move to ES2015 class or use arrow function.

    When React was initially released, there was no idiomatic way to create classes in JavaScript, so we provided our own: React.createClass.

    Later, classes were added to the language as part of ES2015, so we added the ability to create React components using JavaScript classes. Along with functional components, JavaScript classes are now the preferred way to create components in React.

    For your existing createClass components, we recommend that you migrate them to JavaScript classes.

提交回复
热议问题