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-component-log

v1.0.0

Published

HOC for easied debugging/learning of lifecycle methods for React components

Readme

react-component-log

HOC for easier debugging/learning of lifecycle methods of React components

Note: The HOC acts as a shell around your actual component, it is NOT the component itself. Therefore, logging of internal component state is not implemented.

The HOC accepts an optional config object for specifying what should be logged. The config object contains multiple parameters:

printLevel: string, which console function to be used for printing info to the console, defaults to log

shouldPrint: function(prevProps, nextProps), predicate for determining if info should be printed based on previous and next props, defaults to printing all the time, i.e. () => true. Note: only lifecycle methods which are related to component updates take prevProps and nextProps as input parameters, the signature for other lifecycle methods is function()

Boolean flags for configuring which lifecycle methods should be printed (defaults to true for every lifecycle method):

componentWillMount: boolean,
componentDidMount: boolean,
componentWillReceiveProps: boolean,
shouldComponentUpdate: boolean,
componentWillUpdate: boolean,
componentDidUpdate: boolean,
componentWillUnmount: boolean

Exposed functions are withComponentLog and withComponentLogConfig. Internally, both functions delegate the functionality to the same internal HOC. The difference being the following:

withComponentLog(Component, config): HOC, whereas

withComponentLogConfig(config): function(Component): HOC

The second exported function is to avoid modifying the order of execution when composing multiple HOCs.

Example usages of both exports:

import { withComponentLog } from 'react-component-log'
import Counter from './Counter';

const config = {
  printLevel: 'warn',                         // use console.warn
  shouldPrint: (prevProps, nextProps) => {    // print info only when prop value is NOT 3
    if (prevProps && nextProps) {
      return nextProps.value !== 3;
    }
    return true;
  },
  shouldComponentUpdate: false                // skip printing for shouldComponentUpdate
};
const CounterWithComponentLog = withComponentLog(Counter, config);

...
<CounterWithComponentLog value={0} />
import { withComponentLogConfig } from 'react-component-log'
import Counter from './Counter';

const config = {
  printLevel: 'error',                        // use console.error
  componentWillMount: false                   // skip printing for componentWillMount
};

const withCustomConfig = withComponentLogConfig(config);
const CounterWithComponentLog = withCustomConfig(Counter);

...
<CounterWithComponentLog value={0} />