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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-cssx

v1.2.4

Published

Proof of concept about using CSSX in React

Readme

Using vanilla CSS in React application

Yet another way to apply CSS styles in JavaScript. It's not using an inline styling though. It's injecting a <style> tag.

import React from 'react';
import CSSX from 'react-cssx';

class Component extends React.Component {
  render() {
    return (
      <CSSX styles={ this.css() }>
        <h1>Title styled with <i>CSSX</i></h1>
      </CSSX>
    );
  }
  css() {
    var color = '#BADA55';

    return (
      <style>
        h1 {
          color: {{ color }};
        }
        h1 i {
          text-decoration: underline;
        }
      </style>
    );
  }
}

To make the code above works you'll need:

Demo here and here.

CSSX component

<CSSX> component has only one required attribute - styles. It should be an array in the following format:

[
  ['h1', { 'font-size': '32px' }],
  ['h1 small', { 'font-size': '24px', 'font-weight': 'bold' }]
]

Of course writing CSS that way is not really nice. So let's use CSSX and replace it with:

css() {
  return (
    <style>
      h1 {
        font-size: 32px;
      }
      h1 small {
        font-size: 24px;
        font-weight: bold;
      }
    </style>
  );
}

Notice that we should use a function that returns a <style> tag. If we create the <style> tag directly (in the render method for example) we'll get the CSS applied straight away to the whole page.

CSSX component's wrapper

The <CSSX> component generates a <div> by default. Use the data-element attribute to specify the tag that you need:

<CSSX styles={ ... } data-element='h1'>
  <p>Paragraph</p>
</CSSX>

Scoping

If you check some of the examples in a browser you'll see that the created styles are scoped to a specific element. For example:

class Component extends React.Component {
  render() {
    return (
      <section>
        <p>First paragraph</p>
        <CSSX styles={ this.styleParagraph('#F00', 'second') }>
          <p>Second paragraph</p>
        </CSSX>
        <CSSX styles={ this.styleParagraph('#00F', 'third') }>
          <p>Third paragraph</p>
        </CSSX>
      </section>
    );
  }
  styleParagraph(color, text) {
    return (
      <style>
        p {
          color: {{ color }};
        }
        p::before {
          content: {{ text }};
        }
      </style>
    );
  }
}

There are three paragraphs rendered on the screen:

CSSX

The first one does not have any local styles attached. However, the second and the third one are styled differently. They have their own dedicated CSS. CSSX library creates two <style> tags in the <head> of the document.

CSSX

Misc

If this sounds interesting to you follow the links below: