我们需要导入React或者只是{Component,PropTypes}会做什么? [英] Do we need to import React or just {Component, PropTypes} will do?

查看:141
本文介绍了我们需要导入React或者只是{Component,PropTypes}会做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我所有的组件中,我目前正在包含这样的反应:

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

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

我不明白为什么每个人都包括React当它不被使用,因此想检查是否可以安全删除?

I don't see why everyone is including React when it is not used, hence wanted to check if it is safe to remove it?

推荐答案

JSX需要工作。

JSX处理器基本上是这样做的:

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

<div />

到这个:

React.createElement('div')

有办法告诉它使用不同的功能,如 createElement ,而不是 React 始终导入 {createElement} / code> - 这是一个改进的相反的,你不应该这样做。

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.

这篇关于我们需要导入React或者只是{Component,PropTypes}会做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆