Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@babel/plugin-transform-react-display-name
Advanced tools
Add displayName to React.createClass calls
The @babel/plugin-transform-react-display-name npm package is a Babel plugin that adds the displayName property to React components for use in debugging messages and dev tools. It helps to identify components in the React DevTools by providing a readable name, which is particularly useful for anonymous components.
Automatic displayName assignment for React components
This feature automatically assigns a displayName to React components based on their name. This is useful for debugging purposes, as it allows you to see the component's name in the React DevTools.
class MyComponent extends React.Component {}
// Transformed code with displayName:
// MyComponent.displayName = 'MyComponent';
displayName assignment for functional components
Similar to class components, this feature assigns a displayName to functional components, making them easier to identify in the React DevTools.
const MyComponent = () => <div />;
// Transformed code with displayName:
// MyComponent.displayName = 'MyComponent';
displayName assignment for components created with React.createClass
For components created using React.createClass, this plugin also adds a displayName property, which is useful for projects that have not yet migrated to ES6 classes or functional components.
const MyComponent = React.createClass({
render: function() { return <div />; }
});
// Transformed code with displayName:
// MyComponent.displayName = 'MyComponent';
This package is similar to @babel/plugin-transform-react-display-name as it also adds a displayName to React components. However, it is a standalone Babel plugin that might not be as actively maintained or integrated into the Babel ecosystem as the official Babel plugin.
This package provides a utility function to help manually assign a displayName to a React component. It is not a Babel plugin and requires manual usage within the code, unlike the automatic transformation provided by @babel/plugin-transform-react-display-name.
Add displayName to
createReactClass
(andReact.createClass
) calls
In
var foo = React.createClass({}); // React <= 15
var bar = createReactClass({}); // React 16+
Out
var foo = React.createClass({
displayName: "foo"
}); // React <= 15
var bar = createReactClass({
displayName: "bar"
}); // React 16+
npm install --save-dev @babel/plugin-transform-react-display-name
.babelrc
(Recommended).babelrc
{
"plugins": ["@babel/transform-react-display-name"]
}
babel --plugins @babel/transform-react-display-name script.js
require("@babel/core").transform("code", {
plugins: ["@babel/transform-react-display-name"]
});
FAQs
Add displayName to React.createClass calls
The npm package @babel/plugin-transform-react-display-name receives a total of 10,303,507 weekly downloads. As such, @babel/plugin-transform-react-display-name popularity was classified as popular.
We found that @babel/plugin-transform-react-display-name 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.