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-simple-theme

v1.0.1

Published

A pair of HOC's to make theming in react simple.

Readme

react-simple-theme

Build Status npm version

react-simple-theme provides a simple way to add theming support to your react apps. It exposes 2 higher order components (injectThemes and withTheme) to make this possible.

Installation

npm install --save react-simple-theme

Usage

react-simple-theme exports two HOC's, injectThemes and withTheme. injectThemes is used to inject your themes into context and withTheme reads the active theme from context and provides it to your component as a prop.

injectThemes

To use injectThemes you need to first import it from react-simple-theme as shown below:

import { injectThemes } from 'react-simple-theme'

Then you will need a themes object. A sample themes object is shown below:

const themes = {
  defaultTheme: {
    color: 'black',
    outer: 'aliceblue',
  },
  altTheme: {
    color: 'white',
    outer: 'crimson',
  },
}

You will either need to colocate your themes object with your root component or you will need to import it (ex import themes from './themes')

Then you can 'wrap' your root component with `injectThemes' as shown below:

// injectThemes will need the themes object and the name of the 'default theme'
export default injectThemes(themes, 'defaultTheme')(RootComponent)

injectThemes provides your component with two props, activeTheme and changeTheme. activeTheme is a string that represents the name of your currently active theme. changeTheme is a function that accepts a theme name (from your themes object) and then changes the currently active theme to the theme with the name that you have provided it. For example:

const RootComponent = props => (
  <div>
    {/* use props.activeTheme (or this.props.activeTheme is you have a class component) to get access to the name of the active theme */}
    <h1>The currently active theme is {props.activeTheme}</h1>

    {/* use props.changeTheme (or this.props.changeTheme is you have a class component) get access to a function that changes the currently active theme. it takes one argument - the name of the theme you want to make active */}
    <button onClick={() => props.changeTheme('newThemeName')}>Change Theme</button>
  </div>
)

RootComponent.propTypes = {
  activeTheme: PropTypes.string,
  changeTheme: PropTypes.func,
}

withTheme

To use withTheme you need to first import it from react-simple-theme as shown below:

import { withTheme } from 'react-simple-theme'

Then you will need to 'wrap' the component that you want themed. For example:

const NeedsTheme = props => <div>I need a theme!</div>

export default withTheme(NeedsTheme)

That will give your component access to the theme prop:

// theme is available as a prop for your wrapped components
const NeedsTheme = ({theme}) => <div style={{background: theme.background}}>I need a theme!</div>

NeedsTheme.propTypes = {
  theme: PropTypes.shape({
    // the specifics of how your theme object is structured
  })
}

export default withTheme(NeedsTheme)

API

injectThemes

injectThemes accepts the following arguments:

  injectThemes(
    themesObject, // your theme object that contains your themes
    'defaultTheme' // the name of your default theme, this should match a theme in your theme object
  )(
    RootComponent // this is the component that you want to have as your base to inject themes into
  )

injectThemes provides your component with the following props:

  • activeTheme - the name of the currently active theme (useful if you want to display the active theme name to the user)
<div>{this.props.activeTheme}</div> // renders the name of the active theme
// or
<div>{props.activeTheme}</div>
  • changeTheme - a function that takes one argument - the name of the theme you want to make active - and changes the currently active theme to that
this.props.changeTheme('nameOfNewTheme')
// or 
props.changeTheme('nameOfNewTheme')

withTheme

withTheme accepts one arugument, a component that needs a theme:

withTheme(ComponentThatNeedsATheme)

withTheme provides your component with one prop:

  • theme - this is an object with the attributes from the currently active theme

For example if your theme object looked like the following:

const theme = {
  theme1: {
    color: 'red'
  }
}

And 'theme1' was the active theme, then your theme prop would have the following shape:

ComponentThatNeedsATheme.propTypes = {
  theme: PropTypes.shape({
    color: PropTypes.string
  })
}

The shape of the theme prop follows directly from the shape of the active theme in your themes object.