---
id: babel-preset-react
title: @babel/preset-react
sidebar_label: react
---
This preset always includes the following plugins:
- @babel/plugin-syntax-jsx
- @babel/plugin-transform-react-jsx
- @babel/plugin-transform-react-display-name
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
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"],
});
string
, defaults to React.createElement
.
Replace the function used when compiling JSX expressions.
string
, defaults to React.Fragment
.
Replace the component used when compiling JSX fragments.
boolean
, defaults to false
.
Will use the native built-in instead of trying to polyfill behavior for any plugins that require one.
boolean
, defaults to false
.
When spreading props, use inline object with spread elements directly instead of Babel's extend helper or Object.assign
.
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 the env option configuration or js config files.
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 }]]
}
}
}
You can read more about configuring preset options here