Skip to content

Commit 61297d8

Browse files
jyash97CompuIves
authored andcommitted
fix: add undefined check for mostUsedTemplates (codesandbox#3099)
1 parent d927bc5 commit 61297d8

File tree

1 file changed

+23
-19
lines changed
  • packages/app/src/app/pages/Dashboard/Content/CreateNewSandbox

1 file changed

+23
-19
lines changed

packages/app/src/app/pages/Dashboard/Content/CreateNewSandbox/index.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,29 @@ export const CreateNewSandbox: FunctionComponent<Props> = ({
8282
setCreating(true);
8383
};
8484

85-
const buttonName = `Create ${mostUsedSandboxTemplate.niceName} Sandbox`;
86-
const mostUsedSandboxComponent = collectionId ? (
87-
<Container
88-
color={mostUsedSandboxTemplate.color}
89-
onClick={() => createSandbox(mostUsedSandboxTemplate)}
90-
ref={ref}
91-
role="button"
92-
tabIndex={0}
93-
>
94-
{buttonName}
95-
</Container>
96-
) : (
97-
<ContainerLink
98-
color={mostUsedSandboxTemplate.color}
99-
to={sandboxUrl({ id: mostUsedSandboxTemplate.shortid })}
100-
>
101-
{buttonName}
102-
</ContainerLink>
103-
);
85+
let mostUsedSandboxComponent = null;
86+
87+
if (mostUsedSandboxTemplate) {
88+
const buttonName = `Create ${mostUsedSandboxTemplate.niceName} Sandbox`;
89+
mostUsedSandboxComponent = collectionId ? (
90+
<Container
91+
color={mostUsedSandboxTemplate.color}
92+
onClick={() => createSandbox(mostUsedSandboxTemplate)}
93+
ref={ref}
94+
role="button"
95+
tabIndex={0}
96+
>
97+
{buttonName}
98+
</Container>
99+
) : (
100+
<ContainerLink
101+
color={mostUsedSandboxTemplate.color}
102+
to={sandboxUrl({ id: mostUsedSandboxTemplate.shortid })}
103+
>
104+
{buttonName}
105+
</ContainerLink>
106+
);
107+
}
104108

105109
const fromRectDOM = ref.current
106110
? ref.current.getBoundingClientRect()

0 commit comments

Comments
 (0)