Reputation: 399
In some example, I saw :
import React, {
Component
} from 'react';
import {
StyleSheet, Text,...
} from 'react-native';
I know the 'react-native' purpose, but I don't understand why they import 'React' in some example? it makes me confused...
Thanks for your time :)
Upvotes: 0
Views: 85
Reputation: 744
import React from 'react'
is required for JSX to work.
Under the hood, JSX is being transpiled to React.createElement(...)
invocations. So, even though you don't have to type React.createElement()
, JSX still requires React
to be active in the module namespace so that it can do it for you.
Example of what React looks like without the transpilation step.
Upvotes: 1