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

proper-component

v1.1.0

Published

Pass props to third-party React components, whether they expect them or not.

Readme

Usage

Say you want to use this third-party component...

import React from 'react';

class Component extends React.Component {
  render() {
    return (
      <div className="component" style={{ color: 'tomato', fontStyle: 'italic' }}>
        {this.props.children}
      </div>
    );
  }
}

export default Component;

...but it doesn't allow forwarding of props it doesn't care about (stopping you from adding things like ids or aria-*/data-* attributes), nor does it allow you to apply any extra classes or styles.

import React from 'react';
import { render } from 'react-dom';
import Component from 'third-party/Component';

render(
  <Component
    title="aww"
    className="utility-class"
    style={{
      color: 'thistle',
      fontWeight: 'bold'
    }}>
    Aww 😿
  </Component>,
  document.body
);

...will render[1]:

<div class="component" style="color:tomato;font-style:italic">
  Aww 😿
</div>

Well, that sucks.

Now lets use proper-component to make a higher order component from Component, and suddenly, your wildest dreams become possible:

import React from 'react';
import { render } from 'react-dom';
import Component from 'third-party/Component';
import proper from 'proper-component';

const ProperComponent = proper(Component);

render(
  <ProperComponent
    title="yay"
    className="utility-class"
    style={{
      color: 'thistle',
      fontWeight: 'bold'
    }}>
    Yay 🎉
  </ProperComponent>,
  document.body
);

...will render[1]:

<div title="yay" class="component utility-class" style="color:thistle;font-style:italic;font-weight:bold">
  Yay 🎉
</div>;

(...yay)

Installation

npm install proper-component

FAQs / Notes

  • You technically shouldn't be messing with components in this way, because you're breaking encapsulation and responsibility principles and yadda-yadda (zzzZZZzzz), but here's another way of looking at it: If not being able to forward props was the only reason you were ruling out a third party component library in your app, well, this is a win for everyone, isn't it?
  • Under the hood, refs are being forwarded correctly, so they're on the original component, not the HOC. Non-React static class methods are copied to the HOC too (thanks hoist-non-react-statics);
  • Currently, your className will be appended if one already exists on the element and your style will be merged with anything that currently exists. All other props are forwarded.
  • Yes, this works for stateless function components too.
  • This library assumes Object.assign is available in your environment. If you want to support older browsers, you might wanna throw in a polyfill.
  • If you're using React's dev tools in Chrome, you can see how the magic HOC / ref-forwarding stuff works (the component displayNames are a giveaway. Or you can just read the source in /src/index.js. It's only a few lines.
  • To get your head around what proper-component is doing, imagine it just effectively rewrote the third party component example from above as:
class ProperComponent extends React.Component {
  render() {
    const {className = '', style = {}, children ...props} = this.props;

    return (
      <div
        className={`component ${className}`}
        style={{ color: 'tomato', fontStyle: 'italic', ...style }}
        {...props}>
        {children}
      </div>
    );
  }
}

Maybe we can get third-party component library maintainers to do this in the first place, and we wouldn't be in this situation in the first place. I look forward to proper-component's reduncancy 🤞.

.component {
  margin-bottom: 12px;
  border: 2px solid currentColor;
  padding: 6px 10px;
  background-color: papayawhip;
  font-family: sans-serif;
}
.utility-class {
  background-color: rebeccapurple;
}

Contributing

PRs are most welcome on GitHub!

If you clone this project & npm install its development dependencies, you can run tests with npm test and and hack on anything under /src.

I've not gotten around to seeing how this plays with project-specific development setups what use stuff like TypeScript/Flow, or PropTypes checking, so I'd love it if you shared your experiences, or throw a fix my way. Everybody benefits!

Authors