html-attribute-to-react

0.0.5 • Public • Published

html-attribute-to-react

Get the React equivalent of any native HTML attribute.

Why?

There are a number of attributes that work differently between React and HTML. For example:

  • In React, most DOM properties and attributes should be camelCased
  • class in HTML becomes className in React
  • aria-* and data-* attributes stay the same

If you need to programmatically convert HTML to React, this package handles the attribute conversion for you.

Installation

yarn add html-attribute-to-react --save

Usage

import htmlAttributeToReact from 'html-attribute-to-react';

htmlAttributeToReact('class');
// returns 'className'

htmlAttributeToReact('tabindex');
// returns 'tabIndex'

htmlAttributeToReact('aria-label');
// returns 'aria-label'

htmlAttributeToReact('some-custom-attribute');
// returns 'some-custom-attribute'

To get the full attribute map:

import { attributes } from 'html-attribute-to-react';

attributes['class'];
// 'className'

/html-attribute-to-react/

    Package Sidebar

    Install

    npm i html-attribute-to-react

    Weekly Downloads

    42

    Version

    0.0.5

    License

    MIT

    Unpacked Size

    3.63 kB

    Total Files

    4

    Last publish

    Collaborators

    • negomi