babel-plugin-react-require
Babel plugin that adds React import declaration if file contains JSX tags.
Last updated 9 years ago by vslinko .
Original npm · Tarball · package.json
$ npm install babel-plugin-react-require 
SYNC missed versions from official npm registry.

babel-plugin-react-require

Babel plugin that adds React import declaration if file contains JSX tags.

This plugin is only about stateless components that doesn't extends React.Component. If you want to use any other React functions then you should import their by yourself.

Example

Your component.js that contains this code:

export default function Component() {
  return (
    <div />
  );
}

will be transpiled into something like this:

import React from 'react';

export default function Component() {
  /* this part will be transpiled by babel itself as usual */
  return (
    React.createElement('div')
  );
}

Usage

  • Install babel-plugin-react-require.
npm install babel-plugin-react-require --save-dev
  • 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.
{
  "plugins": [
    "react-require"
  ]
}

Current Tags

  • 4.0.3                                ...           latest (4 months ago)

15 Versions

  • 4.0.3                                ...           4 months ago
  • 4.0.2                                ...           a year ago
  • 4.0.1                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 3.1.3                                ...           5 years ago
  • 3.1.2                                ...           5 years ago
  • 3.1.1                                ...           6 years ago
  • 3.1.0                                ...           6 years ago
  • 3.0.2                                ...           6 years ago
  • 3.0.1                                ...           6 years ago
  • 3.0.0                                ...           8 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
Maintainers (1)
Downloads
Total 10
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE