Skip to content

Commit

Permalink
feat(RP): short name
Browse files Browse the repository at this point in the history
- clears react 19 peer incompatibility warning
  • Loading branch information
MiroslavPetrik committed Dec 27, 2024
1 parent 668c6ec commit 5fbda7c
Show file tree
Hide file tree
Showing 8 changed files with 12,231 additions and 6,684 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Handy helper for components which need to have render prop.

## Installation

`yarn add react-render-prop-type`
`npm install -D react-render-prop-type`

## Description

By default the `RenderProp` will extend your props with a `children` render function:

```tsx
import { RenderProp } from 'react-render-prop-type';
import type { RenderProp } from 'react-render-prop-type';

type ColumnProps = {
rowId: string;
Expand All @@ -20,17 +20,17 @@ type ColumnProps = {
const Column = ({
rowId,
attr,
children /* <- default name */,
children /* 👈 default name */,
}: ColumnProps &
RenderProp<{
data: string;
} /* <- props to be passed to the render function */>) => {
} /* 👈 props to be passed to the render function */>) => {
const row = useFakeTable(rowId);

return (
<td>
{children(
{ data: row[attr] } /* <- props to be passed to the render function */
{ data: row[attr] } /* 👈 props to be passed to the render function */
)}
</td>
);
Expand All @@ -52,7 +52,7 @@ const AvatarColumn = (props: ColumnProps) => (
Optionally, you can specify custom prop name, e.g. when you can't use the default children prop.

```tsx
import { RenderProp } from 'react-render-prop-type';
import type { RP } from 'react-render-prop-type'; // short version

type ColumnProps = {
rowId: string;
Expand All @@ -61,9 +61,8 @@ type ColumnProps = {
const Column = ({
rowId,
attr,
render, // <- custom name
}: ColumnProps &
RenderProp<{ data: string }, 'render' /* <- custom name */>) => {
render, // 👈 custom name
}: ColumnProps & RP<{ data: string }, 'render' /* 👈 custom name */>) => {
const row = useFakeTable(rowId); // mock example

return <td>{render({ data: row[attr] })}</td>;
Expand Down Expand Up @@ -91,7 +90,7 @@ const AvatarColumn = (props: ColumnProps) => (
Let's assume we are developing library component `FormField` which renders input and we want to enable our library users to decorate the input with `before` and `after` props. Both of these props receive current input value, so the before/after nodes can be styled accordingly:

```tsx
import { RenderProp } from 'react-render-prop-type';
import type { RenderProp } from 'react-render-prop-type';

type Props = { name: string } & RenderProp<
{ value: string },
Expand Down
Loading

0 comments on commit 5fbda7c

Please sign in to comment.