Skip to content

Commit

Permalink
Merge pull request #356 from FormidableLabs/task/fix-live-preview-types
Browse files Browse the repository at this point in the history
Fix live preview types
  • Loading branch information
carloskelly13 authored May 11, 2023
2 parents eea1186 + a2f5bd6 commit c82c336
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-ligers-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-live": patch
---

Fix live preview types. @kyletsang
17 changes: 9 additions & 8 deletions packages/react-live/src/components/Live/LivePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React, { PropsWithChildren, useContext } from "react";
import React, { useContext } from "react";
import LiveContext from "./LiveContext";

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

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

function LivePreview({ Component = fallbackComponent, ...rest }: Props) {
function LivePreview({ Component = "div", ...rest }: Props): JSX.Element {
const { element: Element } = useContext(LiveContext);
return <Component {...rest}>{Element ? <Element /> : null}</Component>;
}
Expand Down

0 comments on commit c82c336

Please sign in to comment.