Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

oops (#75)

bautistaaaf19e9fea2b8b
diff --git a/src/components/challenge/editor/index.tsx b/src/components/challenge/editor/index.tsx
index 5fbd7304..7e3ab5aa 100644
--- a/src/components/challenge/editor/index.tsx
+++ b/src/components/challenge/editor/index.tsx
@@ -55,13 +55,17 @@ export const CodePanel = ({ challenge }: Props) => {
const defaultCode = useMemo(() => {
// if a user has an existing solution use that instead of prompt
const usersExistingSolution = challenge.Solution?.[0];
+
+ if (!usersExistingSolution) {
+ return challenge.prompt;
+ }
+
const [appendSolutionToThis, separator] = (challenge.prompt as string).split(
/(\/\/ CODE START)/g,
);
const parsedUserSolution = JSON.parse(usersExistingSolution?.code as string) as string;
- return usersExistingSolution
- ? `${appendSolutionToThis ?? ''}${separator ?? ''}${parsedUserSolution}`
- : challenge.prompt;
+
+ return `${appendSolutionToThis ?? ''}${separator ?? ''}${parsedUserSolution}`;
}, [challenge.Solution, challenge.prompt]);
const [code, setCode] = useState(defaultCode as string);