Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@babel/preset-react
Advanced tools
Package description
The @babel/preset-react npm package is a Babel preset that can be used to transform JSX into standard JavaScript. It is commonly used in React applications to allow developers to write JSX, which is a syntax extension for JavaScript that looks similar to HTML. This preset includes the necessary Babel plugins to parse and transform JSX syntax.
Transform JSX
Converts JSX syntax into createElement calls which are understood by React.
const element = <div>Hello, world!</div>;
Support for React Fragments
Allows the use of React Fragments to group a list of children without adding extra nodes to the DOM.
const element = <><div>Item 1</div><div>Item 2</div></>;
Support for JSX Spread Attributes
Enables the spreading of attributes in JSX elements from an object.
const props = { firstName: 'John', lastName: 'Doe' }; const element = <div {...props} />;
Support for JSX Expression Containers
Allows embedding expressions in JSX by wrapping them in curly braces.
const name = 'world'; const element = <div>Hello, {name}!</div>;
This package is similar to @babel/preset-react but is specifically tailored for Create React App projects. It includes additional Babel plugins and configurations suitable for the React scripts bundled with Create React App.
This package is an older preset that includes Babel transformations for ES2015 and React. It is not as up-to-date as @babel/preset-react and is meant for projects that use older JavaScript standards.
This preset is designed for hot module replacement in React applications during development. It is not a direct alternative to @babel/preset-react but offers additional functionality for a specific development workflow.
Readme
Babel preset for all React plugins.
This preset always includes the following plugins:
And with the development
option:
Note: Flow syntax support is no longer enabled in v7. For that, you will need to add the Flow preset.
You can also check out the React Getting Started page
npm install --save-dev @babel/preset-react
.babelrc
(Recommended).babelrc
{
"presets": ["@babel/react"]
}
babel --presets @babel/react script.js
require("@babel/core").transform("code", {
presets: ["@babel/react"]
});
development
boolean
, defaults to false
.
Toggles plugins that aid in development, such as @babel/plugin-transform-react-jsx-self
and @babel/plugin-transform-react-jsx-source
.
This is useful when combined with either a babelrc.js
or env option in a .babelrc configuration:
module.exports = {
presets: [
["@babel/react", {
development: process.env.BABEL_ENV === "development"
}],
],
}
Note: the
env
option will likely get deprecated soon
{
"presets": ["@babel/react"],
"env": {
"development": {
"presets": [
["@babel/react", { "development": true }]
]
}
}
}
FAQs
Babel preset for all React plugins.
We found that @babel/preset-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
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.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).