Skip to content

Commit

Permalink
Update example to use ReactNode over ReactElement
Browse files Browse the repository at this point in the history
  • Loading branch information
nswaldman committed Dec 5, 2023
1 parent 2e5243e commit 60f7672
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/types/PolymorphicComponentProps/PolymorphicComponentProps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type FooComponentProps<T extends ElementType> = PolymorphicComponentProps<
{ barProp: string | undefined }
>;

type FooComponent = <T extends ElementType>(props: FooComponentProps<T>) => ReactElement | null;
type FooComponent = <T extends ElementType>(props: FooComponentProps<T>) => ReactNode | null;

export const Foo: FooComponent = <T extends ElementType>({
as: Component = 'div',
Expand Down Expand Up @@ -68,16 +68,18 @@ type FooComponentProps<T extends ElementType> = PolymorphicComponentPropsWithRef
{ barProp: string | undefined }
>;

type FooComponent = <T extends ElementType>(props: FooComponentProps<T>) => ReactElement | null;

export const Foo: FooComponent = <T extends ElementType>(
{ as: Component = 'div', children, ...otherProps }: FooComponentProps<T>,
ref?: PolymorphicRef<T>,
) => {
return (
<Component {...otherProps} ref={ref}>
{children}
</Component>
);
};
type FooComponent = <T extends ElementType>(props: FooComponentProps<T>) => ReactNode | null;

export const Foo: FooComponent = forwardRef(
<T extends ElementType>(
{ as: Component = 'div', children, ...otherProps }: FooComponentProps<T>,
ref?: PolymorphicRef<T>,
) => {
return (
<Component {...otherProps} ref={ref}>
{children}
</Component>
);
},
);
```

0 comments on commit 60f7672

Please sign in to comment.