Remove selected attributes in each react element by selected conditions
Using npm:
npm install --save-dev babel-plugin-transform-react-remove-prop
or using yarn:
yarn add babel-plugin-transform-react-remove-prop --dev
Add the following line to your .babelrc file.
{
"plugins": ["babel-plugin-transform-react-remove-prop"]
}
{
"plugins": [
[
"babel-plugin-transform-react-remove-prop",
{
"attrs": ["data-test-id"]
}
]
]
}
array, defaults to ["data-test-id"]
Array of attribute names that should be removed from react elements.
// React.createElement
React.createElement('div', { 'data-test-id': 'id' })
// Preact / Object.assign syntax
h('div', Object.assign({}, props, { 'data-test-id': 'id' }))
// Object spread
React.createElement('div', { ...props, 'data-test-id': 'id' })
// Simple attribute
<div data-test-id='id' />
// Object spread
<div {...{ 'data-test-id': 'id' }} />