An open API service indexing awesome lists of open source software.

https://github.com/afeiship/with-props

Enhance component with preset properties.
https://github.com/afeiship/with-props

default-props presets properties react with-props

Last synced: 3 months ago
JSON representation

Enhance component with preset properties.

Awesome Lists containing this project

README

          

# with-props
> Enhance component with preset properties.

[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]

## installation
```shell
npm install @jswork/with-props
```

## usage

```tsx
import withProps from '@jswork/with-props';
import React from 'react';

interface ButtonProps {
text: string;
color?: string;
size?: 'small' | 'medium' | 'large';
}

const Button: React.FC = ({ text, color = 'blue', size = 'medium' }) => {
return (

{text}

);
};

// Create a component with default props
const PrimaryButton = withProps(Button, {
color: 'red',
size: 'large'
});

const App: React.FC = () => {
return (


{/* Uses default props */}

{/* Override default props */}


);
};
```

### Features

- **Type Safe**: Full TypeScript support with proper type inference
- **Props Merging**: Default props are overridden by provided props
- **Simple API**: Just pass component and default props
- **Zero Dependencies**: Lightweight and focused

## license
Code released under [the MIT license](https://github.com/afeiship/with-props/blob/master/LICENSE.txt).

[version-image]: https://img.shields.io/npm/v/@jswork/with-props
[version-url]: https://npmjs.org/package/@jswork/with-props

[license-image]: https://img.shields.io/npm/l/@jswork/with-props
[license-url]: https://github.com/afeiship/with-props/blob/master/LICENSE.txt

[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/with-props
[size-url]: https://github.com/afeiship/with-props/blob/master/dist/index.min.js

[download-image]: https://img.shields.io/npm/dm/@jswork/with-props
[download-url]: https://www.npmjs.com/package/@jswork/with-props