# @solid-primitives/props

> Library of primitives focused around component props.

Latest version **3.2.4** (published 2026-07-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @solid-primitives/props
pnpm add @solid-primitives/props
yarn add @solid-primitives/props
bun add @solid-primitives/props
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.2.4 |
| Published | 2026-07-04 |
| First published | 2021-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 21.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1558 |
| Author | Damian Tarnawski |
| Maintainers | davedbase, lexlohr, thetarnav. |
| Keywords | props, solid, primitives |

## Links

- npm: https://www.npmjs.com/package/@solid-primitives/props
- Repository: https://github.com/solidjs-community/solid-primitives
- Homepage: https://primitives.solidjs.community/package/props
- Issues: https://github.com/solidjs-community/solid-primitives/issues
- npm.io page: https://npm.io/package/@solid-primitives/props

## Dependencies (1)

- [@solid-primitives/utils](https://npm.io/package/@solid-primitives/utils.md) ^6.4.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 3.2.4 (latest) — 2026-07-04
- 4.0.0-next.3 (next) — 2026-08-12
- 3.1.1-beta.0 (beta) — 2023-03-03
- 4.0.0-next.2 — 2026-07-18
- 4.0.0-next.1 — 2026-07-04
- 4.0.0-next.0 — 2026-06-26
- 3.2.3 — 2026-02-24
- 3.2.2 — 2025-06-29
- 3.2.1 — 2025-04-27
- 3.2.0 — 2025-01-22
- 3.1.11 — 2024-03-05
- 3.1.10 — 2024-02-28
- 3.1.9 — 2024-01-16
- 3.1.8 — 2023-08-07
- 3.1.7 — 2023-08-04
- … 34 more at https://npm.io/package/@solid-primitives/props/versions

## README

<p>
  <img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=Props" alt="Solid Primitives Props">
</p>

# @solid-primitives/props

[![size](https://img.shields.io/bundlephobia/minzip/@solid-primitives/props?style=for-the-badge)](https://bundlephobia.com/package/@solid-primitives/props)
[![size](https://img.shields.io/npm/v/@solid-primitives/props?style=for-the-badge)](https://www.npmjs.com/package/@solid-primitives/props)
[![stage](https://img.shields.io/endpoint?style=for-the-badge&url=https%3A%2F%2Fraw.githubusercontent.com%2Fsolidjs-community%2Fsolid-primitives%2Fmain%2Fassets%2Fbadges%2Fstage-3.json)](https://github.com/solidjs-community/solid-primitives#contribution-process)

Library of primitives focused around component props.

- [`combineProps`](#combineprops) - Reactively merges multiple props objects together while smartly combining some of Solid's JSX/DOM attributes.
- [`filterProps`](#filterprops) - Create a new props object with only the property names that match the predicate.

## Installation

```bash
npm install @solid-primitives/props
# or
yarn add @solid-primitives/props
# or
pnpm add @solid-primitives/props
```

## `combineProps`

A helper that reactively merges multiple props objects together while smartly combining some of Solid's JSX/HTML attributes.

Event handlers _(onClick, onclick, onMouseMove, onSomething)_, and refs _(props.ref)_ are chained.

`class`, `className`, `classList` and `style` are combined.

For all other props, the last prop object overrides all previous ones. Similarly to Solid's [mergeProps](https://www.solidjs.com/docs/latest/api#mergeprops).

### How to use it

```tsx
import { combineProps } from "@solid-primitives/props";

const MyButton: Component<ButtonProps> = props => {
  // primitives of a lot of headless ui libraries will provide props to spread
  const { buttonProps } = createButton();
  // they can be combined with user's props easily
  const combined = combineProps(props, buttonProps);

  return <button {...combined} />;
};

// component consumer can provide button props
// they will be combined with those provided by createButton() primitive
<MyButton style={{ margin: "24px" }} />;
```

#### Chaining of event listeners

Every [function/tuple](https://www.solidjs.com/docs/latest/api#on___) property with `on___` name get's chained. That could potentially include properties that are not actually event-listeners – such as `only` or `once`. Hence you should remove them from the props (with [splitProps](https://www.solidjs.com/docs/latest/api#splitprops)).

Chained functions will always return `void`. If you want to get the returned value from a callback, you have to split those props and handle them yourself.

**Warning:** The types for event-listeners often won't correctly represent the values. Chaining is meant only for DOM Events spreading to an element.

```ts
const combined = combineProps(
  {
    onClick: e => {},
    onclick: e => {},
  },
  {
    onClick: [(n, e) => {}, 123],
  },
);
// combined.onClick() will call all 3 of the functions above
```

The default order of execution is left-to-right. If you want to change it, you can use an options object as the last argument: (`reverseEventHandlers: true`)

```ts
const combined = combineProps(
  // props need to be passed in an array
  [{ onClick: () => console.log("parent") }, { onClick: () => console.log("child") }],
  {
    reverseEventHandlers: true,
  },
);
combined.onClick(); // "child" "parent"
```

##### For better reference of how exactly `combineProps` works, see the [TESTS](https://github.com/solidjs-community/solid-primitives/blob/main/packages/props/test/combineProps.test.ts)

### Additional helpers

A couple of lower-lever helpers that power `combineProps`:

#### `stringStyleToObject`

```ts
const styles = stringStyleToObject("margin: 24px; border: 1px solid #121212");
styles; // { margin: "24px", border: "1px solid #121212" }
```

#### `combineStyle`

```ts
const styles = combineStyle("margin: 24px; border: 1px solid #121212", {
  margin: "2rem",
  padding: "16px",
});
styles; // { margin: "2rem", border: "1px solid #121212", padding: "16px" }
```

### DEMO

https://codesandbox.io/s/combineprops-demo-ytw247?file=/index.tsx

## `filterProps`

A helper that creates a new props object with only the property names that match the predicate.

An alternative primitive to Solid's [splitProps](https://www.solidjs.com/docs/latest/api#splitprops) that will split the props eagerly, without letting you change the omitted keys afterwards.

The `predicate` is run for every property read lazily — any signal accessed within the `predicate` will be tracked, and `predicate` re-executed if changed.

### How to use it

Params:

- `props` — The props object to filter.
- `predicate` — A function that returns `true` if the property should be included in the filtered object.

Returns A new props object with only the properties that match the predicate.

```tsx
import { filterProps } from "@solid-primitives/props";

const MyComponent = props => {
  const dataProps = filterProps(props, key => key.startsWith("data-"));

  return <div {...dataProps} />;
};
```

### `createPropsPredicate`

Creates a predicate function that can be used to filter props by the prop name dynamically.

The provided `predicate` function get's wrapped with a cache layer to prevent unnecessary re-evaluation. If one property is requested multiple times, the `predicate` will only be evaluated once.

The cache is only cleared when the keys of the props object change. _(when spreading props from a singal)_ This also means that any signal accessed within the `predicate` won't be tracked.

```tsx
import { filterProps, createPropsPredicate } from "@solid-primitives/props";

const MyComponent = props => {
  const predicate = createPropsPredicate(props, key => key.startsWith("data-"));
  const dataProps = filterProps(props, predicate);

  return <div {...dataProps} />;
};
```

## Changelog

See [CHANGELOG.md](./CHANGELOG.md)

---
_Source: https://npm.io/package/@solid-primitives/props · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
