All skills
hyf0 avatar

/vue-jsx-best-practices

@bc922e4 official
by hyf0hyf0/vue-skills2.9k stars
167

JSX syntax in Vue (e.g., class vs className, JSX plugin config).

Use this Skill: https://skilld.dev/gh/hyf0/vue-skills/vue-jsx-best-practices

This session only. Nothing lands on disk.

referencerender-function-jsx-vue-vs-react.md

≈1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Vue JSX Uses HTML Attributes Not React Conventions

Impact: MEDIUM - Vue's JSX transform uses standard HTML attribute names (class, for) instead of React's JavaScript-friendly names (className, htmlFor). With proper TypeScript configuration, using React conventions like className or htmlFor will produce TypeScript errors, which is good for catching these inconsistencies early. Note that Vue's runtime is lenient and will actually convert these attributes correctly, but using HTML attributes is the recommended practice for consistency with Vue templates and proper type safety.

When writing JSX in Vue, use the same attribute names you would use in regular HTML templates. This is a fundamental difference from React's JSX where class and for are reserved JavaScript keywords.

Task Checklist

  • Use class instead of className in Vue JSX
  • Use for instead of htmlFor in Vue JSX
  • Use standard HTML event names with on prefix (onClick, onInput)
  • When migrating React components to Vue, update all attribute names
  • Configure TypeScript properly for Vue JSX type inference

Incorrect (React-style):

// AVOID: React conventions cause TypeScript errors in Vue JSX
// (Vue runtime is lenient and converts these, but types don't allow them)
export default {
  setup() {
    return () => (
      <div className="container">
        <label htmlFor="email">Email:</label>
        <input id="email" className="input-field" />
      </div>
    )
  }
}
// AVOID: TypeScript will reject className/htmlFor with Vue's JSX types
const Button = () => (
  <button
    className="btn btn-primary"  // TS error: Property 'className' does not exist
    htmlFor="form"               // TS error: Property 'htmlFor' does not exist
  >
    Submit
  </button>
)

Correct (Vue-style):

// CORRECT: Use standard HTML attributes
export default {
  setup() {
    return () => (
      <div class="container">
        <label for="email">Email:</label>
        <input id="email" class="input-field" />
      </div>
    )
  }
}
// CORRECT: Vue TSX with HTML attributes
const Button = () => (
  <button
    class="btn btn-primary"
  >
    Submit
  </button>
)

TypeScript Configuration for Vue JSX

To enable proper type inference and IntelliSense for Vue JSX/TSX, configure your tsconfig.json:

{
  "compilerOptions": {
    "jsx": "preserve",
    "jsxImportSource": "vue"
  }
}

Starting from Vue 3.4, Vue no longer implicitly registers the global JSX namespace, so jsxImportSource is required for TypeScript to use Vue's JSX type definitions.

Vite Configuration

For Vite projects, ensure you have the JSX plugin configured in vite.config.ts:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

export default defineConfig({
  plugins: [vue(), vueJsx()]
})

Other Attribute Differences

React JSX Vue JSX HTML
className class class
htmlFor for for
onChange onInput (for live updates) oninput
tabIndex tabindex tabindex
readOnly readonly readonly

Event Handling in Vue JSX

// Vue JSX event handling
export default {
  setup() {
    const handleClick = () => console.log('clicked')
    const handleInput = (e) => console.log(e.target.value)

    return () => (
      <div>
        <button onClick={handleClick}>Click</button>
        <input onInput={handleInput} />

        {/* Event modifiers via helper */}
        <div onClick={withModifiers(handleClick, ['self'])}>
          Only triggers on self
        </div>
      </div>
    )
  }
}

Reference

Source: SKILL.md on GitHub

No alerts17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides educational documentation and configuration examples for using JSX in Vue projects. It contains no malicious code, unauthorized network access, or sensitive data handling.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    2 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at bc922e4. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 8 months ago
version
2.0.0
author
github.com/vuejs-ai
  • Vue
  • TypeScript
  • jsx
  • react-migration
  • syntax
  • render-functions
  • class-attributes

README badge

README badge for hyf0/vue-skills/vue-jsx-best-practices

Explains Vue JSX syntax and conventions, including attribute naming differences from React (class vs className, on-prefixed event handlers). Use this when migrating React JSX components to Vue or resolving JSX attribute type errors.

Generated from the current SKILL.md.

Does this cover the differences between Vue JSX and React JSX?
Yes. The skill includes a reference guide on render-function JSX differences, covering topics like class vs className attributes.
Will this help me migrate React JSX code to Vue?
Yes. The skill explicitly addresses migrating React JSX to Vue and resolving attribute type errors in that context.
Does this cover JSX plugin configuration?
Yes. The skill covers JSX syntax in Vue including plugin configuration setup.

Generated from the current SKILL.md. These answers refresh after source changes.