在我们写代码的react组件时,不管是无状态组件还是有状态组件,我们在头部都要引入react,然而在代码中又没有使用到react

import React from 'react';

那是因为我们在代码中写了jsx语法,bable在把jsx语法转换成js语法的时候要用到React.createElement()把jsx对象转换成js语法

const Eel = (
<div>
  <h1>hello world</h1>  
</div>
)
// 会转化成
React.createElement("div", null,React.createElement("h1", null, "hello world"));

在转换的时候会用到React.createElement()方法,所以我们要在头部引入react,只有该js文件写了jsx语法及对象



喜欢的朋友记得点赞、收藏、关注哦!!!

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐