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 🙏

© 2025 – Pkg Stats / Ryan Hefner

es6-react-mixins

v0.2.1

Published

Augments ES6 classes with ES6 or traditional React mixins

Readme

es6-react-mixins

Build Status npm version

es6-react-mixins is a module that lets you augment your ES6 React component classes with any number of custom ES6 mixins. You can also use it to merge traditional pre-ES6 React mixin objects into your ES6 React classes.

Inspired by this gist by Sebastian Markbåge the strategy is transient class hierarchies – instead of locking classes into permanent is a roles, class realtionships are assembled and re-assembled at will.

ES6 mixins are functions that return classes. The base parameter is used internally to construct the mixin chain. There's no need to extend React.component, you get that for free.

const es6Mixin = base => class extends base {
  componentWillMount() {
    console.log("augmented componentWillMount");
  }
  render() {
    console.log("augmented render");
  }
};

React components invoke mixins with a call to super.

import mixin from 'es6-react-mixins';
import React from 'react';

class MyComponent extends mixin(es6Mixin) {
  componentWillMount() {
    super.componentWillMount();
  }
  render() {
    super.render();
    return <div>hello/div>;
  }
}

React.render(<MyComponent>, document.body);

The API works with any number of mixins. Obviously order matters with multiple mixins – each super call works its way up the mixin hierarchy.

const mixin1 = base => class extends base {
  componentWillMount() {
    super.componentWillMount();
    console.log("mixin1 componentWillMount");
  }
  render() {
    super.render();
    console.log("mixin1 render");
  }
};

const mixin2 = base => class extends base {
  componentWillMount() {
    super.componentWillMount();
    console.log("mixin2 componentWillMount");
  }
  render() {
    super.render();
    console.log("mixin2 render");
  }
};

class MyComponent extends mixin(mixin1, mixin2) {
  componentWillMount() {
    super.componentWillMount();
  }
  render() {
    super.render();
    return <div>hello/div>;
  }
}

Notice that any mixin can call super, even though there may be no other mixins to hear it. Every mixin descends from a base mixin with no-op implementations of the react lifecycle methods.

es6-react-mixins also accepts traditional plain object mixins (a la pre-ES6 React), adapting them to ES6 style mixins internally.

var reactMixin = {
  componentWillMount: function () {
    console.log
  },
  render: function () {
    this.reactMixin_rendered = true;
  }
};

class MyComponent extends mixin(reactMixin) {
  componentWillMount() {
    super.componentWillMount();
  }
  render() {
    super.render();
    return <div>hello/div>;
  }
}

#Installation

npm install es6-react-mixins

The source is written in es6 but there's an npm prebublish step which transpiles to es5 and dumps into lib directory - which is the default import.

#Testing

npm test

#Contributions

Yes please!