Skip to content

maxsbelt/babel-plugin-transform-react-remove-prop

Repository files navigation

babel-plugin-transform-react-remove-prop

Remove selected attributes in each react element by selected conditions

npm version build status tested with jest Coverage Status

semantic-release Dependencies DevDependencies

Install

Using npm:

npm install --save-dev babel-plugin-transform-react-remove-prop

or using yarn:

yarn add babel-plugin-transform-react-remove-prop --dev

Usage

Add the following line to your .babelrc file.

Without options

{
  "plugins": ["babel-plugin-transform-react-remove-prop"]
}

With options (and their defaults):

{
  "plugins": [
    [
      "babel-plugin-transform-react-remove-prop",
      {
        "attrs": ["data-test-id"]
      }
    ]
  ]
}

Options

attrs

array, defaults to ["data-test-id"]

Array of attribute names that should be removed from react elements.

Supported syntax

JS

// 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' })

JSX

// Simple attribute
<div data-test-id='id' />

// Object spread
<div {...{ 'data-test-id': 'id' }} />

About

Babel plugin that removes selected attributes in each react element by selected conditions

Resources

License

Stars

Watchers

Forks

Packages

No packages published