Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

import React, {Component, PropTypes} from '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?

like image 961
Ilja Avatar asked Jul 05 '16 14:07

Ilja


1 Answers

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.

like image 135
Gosha A Avatar answered Oct 04 '22 10:10

Gosha A