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

prefill

v0.0.3

Published

A tiny utility for preconfiguring React components by prefilling props

Readme

prefill: Partial Application for React Components

A tiny utility for preconfiguring React components by “prefilling” (partially applying) props.

  • Works with intrinsic elements ('div', 'button', …) and function components
  • Forwards refs automatically
  • Merges className (default behavior)
  • Advanced mode: When the second argument is a function instead of an object, it can be used to compose props before they reach a component, to rename or filter them.

See the release article here.


Install

npm i @xoid/prefill

react must be available in your project (this package expects React as a peer-dependency).


Basic usage (object options)

Prefill some props and get a new component where those props become optional.

import { prefill } from '@xoid/prefill'

const OutlinedButton = prefill('button', { className: 'btn btn-outlined' })

// `type` is now optional for consumers
;(() => <OutlinedButton className="my-extra" />)()

With an existing component

import { prefill } from '@xoid/prefill'
import { Button } from './Button'

const PrimaryButton = prefill(Button, { variant: 'primary' })

Function options (extras → pass-down) + prop filtering

When the second argument is a function, it receives a proxy of the incoming props.

Any prop you read inside that function is treated as “extra” and will NOT be passed down to the underlying element/component.

This makes it easy to:

  • create custom props without leaking them to the DOM
  • adapt/rename props
  • compute pass-down props based on extras
import { prefill } from '@xoid/prefill'

type InputExtras = { onValueChange: (value: string) => void }

const Input = prefill('input', (props: InputExtras) => ({
  onChange: (e: React.ChangeEvent<HTMLInputElement>) => props.onValueChange(e.target.value),
}))

// `onValueChange` is used to create `onChange`, and is NOT passed to <input/>
;(() => <Input onValueChange={(v) => console.log(v)} />)()

Filtering rule (exactly)

  • If options is an object: nothing is filtered.
  • If options is a function: props accessed inside it are removed from the props that get passed down.

className merging

By default, if both prefilled options and incoming props provide className, they are concatenated:

const Box = prefill('div', { className: 'base' })
;(() => <Box className="extra" />)() // final className: "base extra"

Refs

The returned component is React.forwardRef(...) and will pass the ref down as ref.

const Input = prefill('input', { className: 'field' })

function Example() {
  const ref = React.useRef<HTMLInputElement>(null)
  return <Input ref={ref} />
}

API

prefill(as, options)

  • as: an intrinsic element key (like 'div', 'input') or a React component.
  • options:
    • an object of prefilled props, or
    • a function (extras) => passDownProps (see “Function options” above)

Named + default export are both provided:

import prefill, { prefill as namedPrefill } from '@xoid/prefill'

Advanced: custom merge “plugin”

Internally, prefill calls a “plugin” function to post-process/merge props. By default it only merges className.

You can provide your own plugin by calling prefill with a custom this:

import { prefill } from '@xoid/prefill'

const mergeStyle = (left: { style?: React.CSSProperties }, right: { style?: React.CSSProperties }) => {
  if (left.style && right.style) right.style = { ...left.style, ...right.style }
}

const styled = prefill.bind(mergeStyle)

const Box = styled('div', { style: { padding: 8 } })
;(() => <Box style={{ color: 'tomato' }} />)() // style => { padding: 8, color: 'tomato' }

Your plugin is called as:

(nextOptions, nextProps) => void

and may mutate nextProps (e.g. to merge className, style, event handlers, etc.).