Coder Social home page Coder Social logo

mk-react / babel-plugin-react-html-attrs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from insin/babel-plugin-react-html-attrs

0.0 1.0 0.0 14 KB

Babel plugin which transforms selected HTML attributes in JSX to their React equivalents

JavaScript 100.00%
mk-react-css mk-react-html

babel-plugin-react-html-attrs's Introduction

babel-plugin-react-html-attrs

Travis npm package

Transforms JSX class attributes into className and for attributes into htmlFor, allowing you to copy and paste HTML into your React components without having to manually edit these particular attributes each time.

Installation & Usage

Install the plugin for Babel >= 6:

npm install --save-dev babel-plugin-react-html-attrs

Then edit your .babelrc to include react-html-attrs:

{
  "plugins": [
    "react-html-attrs"
  ]
}

Plugin Order With transform-react-inline-elements

If you're also using the transform-react-inline-elements plugin, react-html-attrs must be specified before it in your plugin list:

{
  "plugins": [
    "react-html-attrs",
    "@babel/plugin-transform-react-inline-elements"
  ]
}

ESLint Configuration

If you're using eslint-plugin-react's' no-unknown-property rule, as of v5.2.0 you can configure it to ignore usage of class and for in your JSX like so:

{
  "react/no-unknown-property": [2, {"ignore": ["class", "for"]}]
}

Caveats

Read facebook/react#4433 for the reasoning behind why React treats these attributes the way it does and the potential gotchas which await you if you use this plugin (an old version of the JSX transformer used to perform this transformation).

It's fairly common to access a className prop in user-defined components, and if you get used to using a class prop instead, that you're actually passing className is surprising behaviour.

Attribution

Testing setup cloned from gaearon/babel-plugin-react-transform.

MIT Licensed

babel-plugin-react-html-attrs's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.