Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@babel/plugin-transform-react-jsx-self
Advanced tools
The @babel/plugin-transform-react-jsx-self plugin is used with Babel to transform JSX code in React. It adds a __self attribute to JSX elements which is used by React for development tools to provide more informative error messages and warnings. This attribute includes a reference to the component that created each element, which can be helpful for debugging purposes.
Adding __self attribute to JSX elements
This feature automatically adds a __self attribute to every JSX element, which is set to 'this' (the current React component instance). This is useful for React's development mode error messages and warnings, as it helps identify which component the JSX element came from.
class MyComponent extends React.Component {
render() {
return <div>Hello, world!</div>;
}
}
// Transformed JSX with @babel/plugin-transform-react-jsx-self
// <div __self={this}>Hello, world!</div>
This plugin transforms JSX syntax into createElement calls. It is similar to @babel/plugin-transform-react-jsx-self but does not automatically add the __self attribute. It is a more general JSX transformation plugin.
Similar to @babel/plugin-transform-react-jsx-self, this plugin adds source information to JSX elements by adding a __source attribute. This includes the file name and line number of the JSX element, which is also useful for debugging. It complements the __self attribute by providing additional context about where the element was defined.
While not a Babel plugin, react-hot-loader is a package that enables hot reloading for React components. It also helps with debugging by preserving the internal state of components when the code is updated. It's similar in the sense that it enhances the development experience, but it does not modify the JSX syntax like @babel/plugin-transform-react-jsx-self.
Add a __self prop to all JSX Elements
See our website @babel/plugin-transform-react-jsx-self for more information.
Using npm:
npm install --save-dev @babel/plugin-transform-react-jsx-self
or using yarn:
yarn add @babel/plugin-transform-react-jsx-self --dev
v7.24.6 (2024-05-24)
babel-helper-create-class-features-plugin
, babel-plugin-transform-class-properties
babel-core
, babel-generator
, babel-plugin-transform-modules-commonjs
babel-helper-create-class-features-plugin
, babel-plugin-proposal-decorators
babel-helpers
, babel-plugin-proposal-decorators
, babel-runtime-corejs3
babel-parser
, babel-plugin-transform-typescript
cls.fn<C> = x
(@liuxingbaoyu)babel-core
, babel-helpers
, babel-plugin-transform-runtime
, babel-preset-env
, babel-runtime-corejs2
, babel-runtime-corejs3
, babel-runtime
babel-helpers
tsconfig.json
for @babel/helpers/src/helpers
(@nicolo-ribaudo)babel-cli
, babel-helpers
, babel-plugin-external-helpers
, babel-plugin-proposal-decorators
, babel-plugin-transform-class-properties
, babel-plugin-transform-modules-commonjs
, babel-plugin-transform-modules-systemjs
, babel-plugin-transform-runtime
, babel-preset-env
, babel-runtime-corejs2
, babel-runtime-corejs3
, babel-runtime
babel-parser
, babel-traverse
FAQs
Add a __self prop to all JSX Elements
We found that @babel/plugin-transform-react-jsx-self 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.