Pork Jackson
Pork Jackson

Reputation: 399

what different import 'react' and 'react-native' in same file

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

Answers (1)

Denny
Denny

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

Related Questions