Skip to content

Commit c82c336

Browse files
Merge pull request #356 from FormidableLabs/task/fix-live-preview-types
Fix live preview types
2 parents eea1186 + a2f5bd6 commit c82c336

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

.changeset/nice-ligers-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-live": patch
3+
---
4+
5+
Fix live preview types. @kyletsang

packages/react-live/src/components/Live/LivePreview.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import React, { PropsWithChildren, useContext } from "react";
1+
import React, { useContext } from "react";
22
import LiveContext from "./LiveContext";
33

4-
type Props = {
5-
Component?: React.ComponentType<PropsWithChildren<Record<string, unknown>>>;
6-
};
4+
type Props<T extends React.ElementType = React.ElementType> = {
5+
Component?: T;
6+
} & React.ComponentPropsWithoutRef<T>;
77

8-
const fallbackComponent = (
9-
props: PropsWithChildren<Record<string, unknown>>
10-
) => <div {...props} />;
8+
function LivePreview<T extends keyof JSX.IntrinsicElements>(
9+
props: Props<T>
10+
): JSX.Element;
11+
function LivePreview<T extends React.ElementType>(props: Props<T>): JSX.Element;
1112

12-
function LivePreview({ Component = fallbackComponent, ...rest }: Props) {
13+
function LivePreview({ Component = "div", ...rest }: Props): JSX.Element {
1314
const { element: Element } = useContext(LiveContext);
1415
return <Component {...rest}>{Element ? <Element /> : null}</Component>;
1516
}

0 commit comments

Comments
 (0)