Skip to content

charliedavison/babel-plugin-react-attribute-scope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-react-attribute-scope

Allows for automatic namespacing of props and attribute values to the React component where they are used.

This is useful for automated testing where you want to ensure your data-hooks, dataIds or whatever convention you are using are unique on an individual page.

For example in login-form.jsx

<Button dataHook="button" /> becomes <Button dataHook="login-form-button" />

Usage

In babel.config.js, add react-attribute-scope to your plugins, and specify the jsxProperty and htmlAttribute you want to transform.

  const plugins = [
    ['react-attribute-scope', { jsxProperty: 'dataHook', htmlAttribute: 'data-hook' }],
    ...
    ];

About

Automatically modify attribute values with React component scope.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published