Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
babel-plugin-react-add-property
Advanced tools
a Babel plugin for adding a data property to React components
This is a small Babel plugin for adding data attributes to React JSX elements. I created this plugin to add meaningful identifiers for styled components. This allows our components to have a designated attribute for end-to-end integration tests (without having to add them manually).
<div class="Page-jLerck lhFHrB">
<div class="Header-dJBcYZ dqmObD">...</div>
<div class="Body-MnRsT gzvZiS">...</div>
</div>
<div class="Page-jLerck lhFHrB" data-test="Page">
<div class="Header-dJBcYZ dqmObD" data-test="Header">
...
</div>
<div class="Body-MnRsT gzvZiS" data-test="Body">
...
</div>
</div>
This package is available on npm as babel-plugin-react-add-property
, and you can find it
here.
To install the latest stable version with Yarn:
$ yarn add --dev babel-plugin-react-add-property
...or with npm:
$ npm install babel-plugin-react-add-property
.babelrc
(Recommended)If you don't provide a property name, the attribute name will default to data-test
.
NOTE: As these attributes are intended only for testing purposes, we're telling Babel to only use the plugin in our development environment. If you'd like to use this plugin in other environments, you'll need to specify them as well.
// .babelrc
{
"env": {
"development": {
"plugins": ["react-add-property"]
}
}
}
However, if you'd like to have a custom attribute name, you can pass it in with your .bablerc
.
// .babelrc
{
"env": {
"development": {
"plugins": [["react-add-property", { "property": "data-qa" }]]
}
}
}
This custom config would transform this div:
<div class="Header-dJBcYZ dqmObD">...</div>
to look like this:
<div class="Header-dJBcYZ dqmObD" data-qa="Header">
...
</div>
babel --plugins react-add-property script.js
without options:
require('babel-core').transform('code', {
plugins: ['react-add-property'],
});
with options:
require('babel-core').transform('code', {
plugins: [['react-add-property', { property: 'data-qa' }]],
});
I am thankful for any contributions made by the community. By contributing you agree to abide by the Code of Conduct in the Contributing Guidelines.
FAQs
a Babel plugin for adding a data property to React components
The npm package babel-plugin-react-add-property receives a total of 13 weekly downloads. As such, babel-plugin-react-add-property popularity was classified as not popular.
We found that babel-plugin-react-add-property demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.