npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-h-tag

v1.1.0

Published

Automate heading levels for your React app.

Downloads

3

Readme

react-h-tag

Automate heading levels for your React app.

Installation

npm install react-h-tag

Or, if you prefer yarn:

yarn add react-h-tag

Requirements

react-h-tag uses React 16.9.0+ as a peer dependency.

Usage

In order to create a heading element, use the H component.

import { H } from 'react-h-tag'

function App() {
  return (
    <div>
      <h1>some fancy big h1</h1>

      <H>this will be an h2</H>
    </div>
  )
}

By default all H components will render as <h2> elements—in order to automatically increase heading levels all you need to do is wrap H in an HLevel.

import { H, HLevel } from 'react-h-tag'

function App() {
  return (
    <div>
      <h1>some fancy big h1</h1>

      <H>second best, this is a h2</H>

      <HLevel>
        <H>just a modest h3</H>
      </HLevel>
    </div>
  )
}

You can nest HLevels to let the heading system increase the heading level even further. However, the heading level maxes out at <h6> since there's no such thing as <h7>, <h8>, etc.

import { H, HLevel } from 'react-h-tag'

function App() {
  return (
    <div>
      <h1>some fancy big h1</h1>

      <H>second best, this is a h2</H>

      <HLevel>
        <H>just a modest h3</H>

        <HLevel>
          <H>smaller now, it's a h4</H>

          <HLevel>
            <H>h5</H>

            <HLevel>
              <H>h6</H>

              <HLevel>
                <H>still an h6, we maxed it out.</H>
              </HLevel>
            </HLevel>
          </HLevel>
        </HLevel>
      </HLevel>
    </div>
  )
}

Adjusting heading levels

By default, you shouldn't have to worry much about your heading levels. Just drop H components throughout your app and they'll figure out what they need to be based on whether they're inside an HLevel context or not.

However, occasionally you have two heading levels side by side, like in the following HTML:

<div>
  <h2>heading 2</h2>
  <h3>heading 3</h3>
</div>

As a convenience for these situations, you can use the increase prop to adjust the level of the current H tag

<div>
  <H>heading 2</H>
  <H increase={1}>heading 3</H>
</div>

Trade-Offs & Caveats

h1 tags

By design, react-h-tag does not allow you to create h1 tags. Since you should only have a single h1 tag on your page, there isn't much need to dynamically figure out h1 tags. This decisions helps you avoid accidentally shipping multiple h1 tags and shooting yourself in the foot.