Skip to content

Commit

Permalink
fix: Better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
CTNicholas committed Oct 4, 2022
1 parent 090a5ae commit c9418a1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions sandpack-react/src/presets/Sandpack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const Sandpack: SandpackInternal = (props) => {

const hasRightColumn =
props.options?.showConsole || props.options?.showConsoleButton;
const RightColumn = hasRightColumn ? SandpackStack : React.Fragment;

const rightColumnStyle = {
flexGrow: previewPart,
Expand All @@ -92,12 +93,10 @@ export const Sandpack: SandpackInternal = (props) => {
height: props.options?.editorHeight, // use the original editor height
};

const RightColumn: React.FC<{ children: React.ReactNode }> = ({ children }) =>
hasRightColumn ? (
<SandpackStack style={rightColumnStyle}>{children}</SandpackStack>
) : (
<React.Fragment>{children}</React.Fragment>
);
const rightColumnProps = React.useMemo(
() => (hasRightColumn ? { style: rightColumnStyle } : {}),
[hasRightColumn]
);

/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
const templateFiles = SANDBOX_TEMPLATES[props.template!] ?? {};
Expand Down Expand Up @@ -134,7 +133,7 @@ export const Sandpack: SandpackInternal = (props) => {
/>

{/* @ts-ignore */}
<RightColumn>
<RightColumn {...rightColumnProps}>
{mode === "preview" && (
<SandpackPreview
actionsChildren={actionsChildren}
Expand Down

0 comments on commit c9418a1

Please sign in to comment.