UNPKG

1.01 kBMarkdownView Raw
1# babel-plugin-react-require
2
3Babel plugin that adds React import declaration if file contains JSX tags.
4
5This plugin is only about stateless components that doesn't extends `React.Component`.
6If you want to use any other React functions then you should import their by yourself.
7
8## Example
9
10Your `component.js` that contains this code:
11
12```js
13export default function Component() {
14 return (
15 <div />
16 );
17}
18```
19
20will be transpiled into something like this:
21
22```js
23import React from 'react';
24
25export default function Component() {
26 /* this part will be transpiled by babel itself as usual */
27 return (
28 React.createElement('div')
29 );
30}
31```
32
33## Usage
34
35* Install `babel-plugin-react-require`.
36
37```
38npm install babel-plugin-react-require --save-dev
39```
40
41* Add `react-require` into `.babelrc`. This plugin should be defined before `transform-es2015-modules-commonjs` plugin because it's using ES2015 modules syntax to import `React` into scope.
42
43```json
44{
45 "plugins": [
46 "react-require"
47 ]
48}
49```