JSPM

babel-plugin-jsx-attributes-array-to-object

0.2.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 988
    • Score
      100M100P100Q121242F
    • License MIT

    A tool for transforming jsx attributes array to object

    Package Exports

    • babel-plugin-jsx-attributes-array-to-object

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-jsx-attributes-array-to-object) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    babel-plugin-jsx-attributes-array-to-object

    A tool for transforming jsx attributes array to object.

    example

    var a = { color: 'red' };
      
    <div style={[a, { color: 'gray' }]}></div>

    and the configure like this:

    // .babelrc
    [
      syntaxJSX,
      [require('babel-plugin-jsx-attributes-array-to-object
    '), { attributes: ['style'] }],
    ]

    the code will be transformed:

    var a = {
      color: 'red'
    };
    <div style={__mergeObject(a, {
      color: 'gray'
    })}></div>;
    
    function __mergeObject(...args) {
      return args.reduce((obj, next) => {
        obj = Object.assign(Object.assign({}, obj), next);
        return obj;
      }, {});
    }

    Usage

    Step 1: Install

    yarn add --dev babel-plugin-jsx-attributes-array-to-object

    or

    npm install --save-dev babel-plugin-jsx-attributes-array-to-object

    Step 1: Configure .babelrc

    {
      plugins: [
        [require('babel-plugin-jsx-attributes-array-to-object')]
      ]
    }