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-compinators

v1.0.55

Published

React component combinators

Readme

λ⚛ React Compinators

A tiny library of functional utilities for composing React components: compinators = Component Combinators.

Synopsis

Create three new components by partially applying the <Label> component color prop, one for each member of the COLORS union:

import {String} from 'effect'
import {unionVariants} from 'react-compinators'

const [ GreenLabel, YellowLabel, RedLabel ] = unfoldProp(
  Label,             // Component that we will wrap three times.
  'color',           // Prop that we will partially apply.
)(
  COLORS,            // Array of union members.
  String.capitalize, // Optional function will be used to compute variant
                     // displayName from its `color` prop.
) 

See the tutorial for more info.

Quick Start

> pnpm add react-compinators

You can then import any of the exported functions from the package react-compinators. For example to import the assume function in your component:

import {assume} from 'react-compinators'

Why?

React offers Far More Than One Way to compose and repurpose components. For example, you can fiddle with their props and wrap them in various ways. Whatever you do, eventually you will end up with a new component.

The functions here provide a lighter alternative, via functions that React calls Higher Order Components (HOCs).

Consider a colored <Label> component with props of type:

interface LabelProps {
  text: string
  color: 'red' | 'yellow' | 'green'
}

If we find ten yellow labels in our code, we could create a new <YellowLabel> component, where the color is fixed on yellow:

const YellowLabel = ({text: string}) => (
  <Label {...{text}} color='yellow' />
)
// Using:
<YellowLabel text='Hello World!' />

Using the assumeProp combinator from this library, we have lighter alternative that avoids JSX:

import {assumeProp} from 'react-compinators'
import type {FC} from 'react'
// Note correct computed type for YellowLabel props.
const YellowLabel: FC<{text: string}> = assumeProp(Label, {color: 'yellow'})
// Using:
<YellowLabel text='Hello World!' />

The result is exactly the same. The style of HOCs you will find here is supported by React Dev Tools so the debug experience of the <YellowLabel> should similar, except it will appear under the name <Yellow(Label)>.

I have found these functions helpful in all kinds of situations:

  1. Cross-cutting concerns.
    • For example when different parts of an application require functionality such as:
      1. Authentication guards.
      2. Memoizing component props in local storage, lest they be lost on browser refresh.
      3. Logging
    • But you would rather not touch the source code of components involved.
  2. When more components but fewer props is preferable to fewer components but more props.
    • For example, when writing components for a design-system driven library, it is common to create a highly configurable component, for example a <Button>, and then derive various variants from it, for example: <PrimaryButton> or <SecondaryButton>.
      • These variants are often just different combinations of values for the props of the <Button>.
      • Functions like withVariants reduce boilerplate and clarify intent for such tasks.
    • Describing changes to components as plain old data lets you manipulate definitions as data, for example to customize a color, or to add a debug panel overlay to all children of a component.
  3. The functions here are all well-known higher-order functions, for example curry, that have been specialized for React components.
    • This helps you take pieces of components out of JSX, and into your regular functional programming pipelines. When a simple function would suffice, these combinators help your stay in a single “world”, and leave the JSX more focused on its UI concerns.
    • Just as a curry combinator for functions is useful enough to deserve its own name, so too for assumeProps when dealing with React components.

Features

A Contravariant instance for Effect and a bunch of combinators.

If you squint hard you will see they are all just specializations of mapProps.

The Combinators

  1. Currying
    1. assumeProp (src)
    2. unfoldProp (src)
    3. assumeProps (src)
  2. Children
    1. modChildren src)
    2. appendChildren (src)
    3. prependChildren (src)
  3. Mapping
    1. mapProp (src)
    2. mapProps (src)
    3. modProp (src)
    4. modOptionalProp (src)
    5. withDefault (src)
    6. requireProp (src)
    7. renameProps (src)
    8. renameProp (src)
    9. omitProps (src)
  4. Styles
    1. modStyle (src)
    2. withStyle (src)
    3. withDefaultStyle (src)
    4. modCssVar (src)
  5. Variants
    1. withVariants (src)

Roadmap

  1. Guards and branches
  2. Layout and children
  3. Debug and pointcuts

See Also

  1. Tutorial
  2. API Reference
  3. recompose