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-as-hoc

v0.1.0

Published

Make those pesky render prop components back into HOCs

Readme

react-as-hoc

When you wanted an HOC but some jerk gave you a render-prop component.

NPM JavaScript Style Guide

Install

yarn add react-as-hoc

API

This function curries a few functions to properly translate all the data in the correct ways. The API is effectively:

type RenderPropFunction = ({children: Function}) => Function;
type PropFn = (props: Object) => Object;
type TransformMethod = (...renderArgs:any) => Object;

type AsHoc = (RenderPropsFunction, ?PropFn) => TransformMethod => React$Component;

Explanation:

const wrappedButNeedsTransform = asHoc(
  // This is the render prop component you are wanting to change into an HOC
  renderPropFn,

  // If this render prop component takes an props itself, you can optionally create the object of props
  // it will receive. The function takes in the props of the finally wrapped component so you can dynamically
  // pass props into the render prop component.
  props => ({foo: props.foo, bar: 2})
);

/*
 * Since render prop functions give you named arguments, there isnt a great way for us to know what the key name for the prop should be.
 * This `TransformMethod` lets you assign proper keys. It does require you to know what the render prop will return. But That is a requirement
 * for using any render prop component.
 * For this example, let's assume our render prop component internally looks like this:
 *
 * ```js
 * const GetCoordinates = ({children}) => children(1, 2);
 * ```
 *
 * Our GetCoordinates would often be used like `<GetCoordinates>{(x, y) => ...}</GetCoordinates>`
 *
 * Here we just trasform the names args into an object to spread into our component
 */
const hoc = wrappedButNeedsTransform((x, y) => ({x, y}));

/*
 * Now we have our HOC and can wrap our component with it. Which will then get x and y as props.
 */
const Component = hoc(({x, y}) => <div>{x} {y}</div>);

Usage

This example is based on react-motion's render Prop API.

// react-motion-hoc.js
import asHoc from 'react-as-hoc';
import { Motion, spring } from 'react-motion';

export default asHoc(Motion, (ownProps) => ({defaultStyle: {x: 0}, style={x: spring(10)}}))(value => ({value}));
// my-component.js
import React from 'react';
import motionHoc from './react-motion-hoc';


class MyComponent extends React.Component<{value: Object}> {
  constructor(props) {
    super(props)

    // value from Motion's render prop API
    console.log(props.value.x);
  }
}

export default motionHoc(MyComponent);

Why

There are some situations where render props just don't make sense. Other times, stylisticly you'd rather have an HOC. The decision should be in your court. Check out all the cool render-prop APIs you can make into HOCs!

License

MIT © Blaine Kasten