0

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 :)

Pork Jackson
  • 339
  • 1
  • 15

1 Answers1

1

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.

Denny
  • 744
  • 4
  • 10