Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@babel/preset-react
Advanced tools
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 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.
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
Without options:
{
"presets": ["@babel/preset-react"]
}
With options:
{
"presets": [
["@babel/preset-react", {
"pragma": "dom", // default pragma is React.createElement
"pragmaFrag": "DomFrag", // default is React.Fragment
"throwIfNamespace": false // defaults to true
}]
]
}
babel --presets @babel/preset-react script.js
require("@babel/core").transform("code", {
presets: ["@babel/preset-react"]
});
pragma
string
, defaults to React.createElement
.
Replace the function used when compiling JSX expressions.
pragmaFrag
string
, defaults to React.Fragment
.
Replace the component used when compiling JSX fragments.
useBuiltIns
boolean
, defaults to false
.
Will use the native built-in instead of trying to polyfill behavior for any plugins that require one.
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:
throwIfNamespace
boolean
, defaults to true
.
Toggles whether or not to throw an error if a XML namespaced tag name is used. For example:
<f:image />
Though the JSX spec allows this, it is disabled by default since React's JSX does not currently have support for it.
module.exports = {
presets: [
["@babel/preset-react", {
development: process.env.BABEL_ENV === "development",
}],
],
}
Note: the
env
option will likely get deprecated soon
{
"presets": ["@babel/preset-react"],
"env": {
"development": {
"presets": [
["@babel/preset-react", { "development": true }]
]
}
}
}
FAQs
Babel preset for all React plugins.
The npm package @babel/preset-react receives a total of 9,048,306 weekly downloads. As such, @babel/preset-react popularity was classified as popular.
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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.