Vue JSX Prop Merging Helper

2.0.3 · maintenance · verified Sun Apr 19

babel-helper-vue-jsx-merge-props is an internal Babel helper package designed to facilitate the merging of props when using JSX syntax within Vue.js applications. Specifically, it handles the transformation of JSX spread attributes into the Vue Virtual DOM's `data` object, ensuring correct aggregation of properties, attributes, and event handlers. This package is a dependency of `@vue/babel-preset-jsx` and `@vue/babel-plugin-transform-vue-jsx` (for Vue 2.x) and is not intended for direct consumption by application developers. The current stable version, as specified, is 2.0.3. Its release cadence is tightly coupled with updates to Vue's JSX transformation tools, primarily for Vue 2.x projects. For Vue 3, `@vue/babel-plugin-jsx` handles JSX transformations and prop merging internally, superseding the need for this helper directly.

Common errors

Warnings

Install

Imports

Quickstart

Illustrates Babel configuration for Vue 2 JSX, showing how this helper enables prop spreading within components, without direct code usage.

/*
This package is an internal Babel helper and is not directly used in application code.
Instead, it is a dependency of Babel plugins/presets that enable Vue JSX.
Below is an example of how you would configure Babel to enable Vue 2 JSX support,
which implicitly uses this helper for prop merging.
*/

// babel.config.js
module.exports = {
  presets: [
    // For Vue 2.x projects using JSX
    ['@vue/babel-preset-jsx', { /* options, e.g., 'compositionAPI': true for Vue 2.7 */ }]
    // For Vue 3.x, use '@vue/babel-plugin-jsx' instead, which has its own merge logic.
  ]
};

// MyComponent.vue (example using JSX with prop spreading)
<script lang="jsx">
import Vue from 'vue';

export default Vue.extend({
  props: {
    baseProps: { type: Object, default: () => ({}) },
    extraClass: { type: String, default: '' },
  },
  render() {
    const mergedProps = { class: `my-component ${this.extraClass}`, ...this.baseProps };
    return (
      <div
        {...mergedProps}
        onClick={() => console.log('Component clicked with merged props.')}
      >
        Hello from JSX Component!
      </div>
    );
  },
});
</script>

view raw JSON →