Socket
Socket
Sign inDemoInstall

babel-plugin-react-require

Package Overview
Dependencies
0
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-react-require

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


Version published
Weekly downloads
91K
decreased by-1.87%
Maintainers
2
Install size
11.8 kB
Created
Weekly downloads
 

Readme

Source

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"
  ]
}

Keywords

FAQs

Last updated on 02 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc