Import statements: with or without React?

前端 未结 2 1113
甜味超标
甜味超标 2021-01-11 15:11

There\'s a little bit of a debate at work on whether it is necessary to import React in stateless components and I can\'t find any docs about it. So:

         


        
2条回答
  •  青春惊慌失措
    2021-01-11 15:50

    Use option 1 because babel will transform your jsx

    to
    React.createElement("button", { onClick: action }, "Submit");

    So as you see react must be in scope. You have two options:

    1. import React from 'react';
    2. or define React globally

提交回复
热议问题