Do we need to import React or just {Component, PropTypes} will do?

后端 未结 1 775
醉话见心
醉话见心 2020-12-07 00:44

in all of my components I am currently including react like this:

import React, {Component, PropTypes} from \'react\'

I don\'t see why ever

相关标签:
1条回答
  • 2020-12-07 01:37

    It is needed for JSX to work.

    What the JSX processor does, essentially, is turn this:

    <div />
    

    into this:

    React.createElement('div')
    

    There are ways to tell it to use a different function, like createElement and then instead of React always import {createElement} — which is the opposite of an improvement, and you shouldn't do it anyway.

    0 讨论(0)
提交回复
热议问题