1. babel-plugin-transform-react-jsx
Turn JSX into React function calls
babel-plugin-transform-react-jsx
Package: babel-plugin-transform-react-jsx
Created by: babel
Last modified: Sun, 13 Nov 2022 06:08:25 GMT
Version: 6.24.1
License: MIT
Downloads: 2,056,530
Repository: https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx

Install

npm install babel-plugin-transform-react-jsx
yarn add babel-plugin-transform-react-jsx

babel-plugin-transform-react-jsx

Turn JSX into React function calls

Example

React

In

 var profile = <div>
  <img src="avatar.png" className="profile" />
  <h3>{[user.firstName, user.lastName].join(' ')}</h3>
</div>;

Out

 var profile = React.createElement("div", null,
  React.createElement("img", { src: "avatar.png", className: "profile" }),
  React.createElement("h3", null, [user.firstName, user.lastName].join(" "))
);

Custom

In

 /** @jsx dom */

var { dom } = require("deku");

var profile = <div>
  <img src="avatar.png" className="profile" />
  <h3>{[user.firstName, user.lastName].join(' ')}</h3>
</div>;

Out

 /** @jsx dom */

var dom = require("deku").dom;

var profile = dom( "div", null,
  dom("img", { src: "avatar.png", className: "profile" }),
  dom("h3", null, [user.firstName, user.lastName].join(" "))
);

Installation

 npm install --save-dev babel-plugin-transform-react-jsx

Usage

Via .babelrc (Recommended)

.babelrc

Without options:

 {
  "plugins": ["transform-react-jsx"]
}

With options:

 {
  "plugins": [
    ["transform-react-jsx", {
      "pragma": "dom" // default pragma is React.createElement
    }]
  ]
}

Via CLI

 babel --plugins transform-react-jsx script.js

Via Node API

 require("babel-core").transform("code", {
  plugins: ["transform-react-jsx"]
});

Options

pragma

string, defaults to React.createElement.

Replace the function used when compiling JSX expressions.

Note that the @jsx React.DOM pragma has been deprecated as of React v0.12

useBuiltIns

boolean, defaults to false.

When spreading props, use Object.assign directly instead of Babel's extend helper.

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin