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

hocompose

v2.0.0

Published

Using Higher-Order Components in React is great for composition: they allow to decouple rendering logic from component lifecycle.

Downloads

25

Readme

hocompose

npm version Build Status

A library to compose higher-order components into one.

Note: 1.0.0 is a rewrite

Higher-order components

Using Higher-Order Components (HOCs) in React is great for composition. They allow to decouple rendering logic from life-cycle logic. HOCs are good for extracting logic from components, so it can be applied to other components without duplicating code.

Sharing a specific component behaviour between many components is easy with higher-order components. However, because of nesting, adding multiple behaviours to a component is done at the expense of component instances.

Composition

Nesting rendering logic makes total sense, this is how one builds a UI consisting of a tree of components. But, why should one follow the same pattern to add a series of behaviours to a component?

This is what hocompose enables: composing behaviours together in only one higher-order component. Think of it as the best of higher-order components, decorators and mixins.

Installation and usage

npm install --save hocompose
import compose from 'hocompose';
import pure from 'hocompose/behaviours/pure';
import setContext from 'hocompose/behaviours/setContext';
import getContext from 'hocompose/behaviours/getContext';

Key concepts

  • Only functions with closures, hocompose is thisless
  • State values are serialised to props
  • componentWillMount and componentDidMount functions can both return functions executed in componentWillUnmount

Docs

Quick example

import React from 'react';
import compose from 'hocompose';
import pure from 'hocompose/behaviours/pure';

const windowSizeBehaviour = (model) => {
    const buildState = () => ({
        width: window.innerWidth,
        height: window.innerHeight
    });

    return {
        state: buildState(),
        componentDidMount(model, setState) {
            const resizeHandler = () => setState(buildState());
            
            window.addEventListener('resize', resizeHandler);

            // Return an unmount function
            return () => window.removeEventListener('resize', resizeHandler);
        }
    };
};

const MyView = (props) => <div>This is my view, { props.width }x{ props.height }</div>;

export default compose(pure, windowSizeBehaviour)(MyView);