-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeScriptPlayground.tsx
More file actions
30 lines (24 loc) · 1.17 KB
/
TypeScriptPlayground.tsx
File metadata and controls
30 lines (24 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"use client"
import { useContext, useEffect, useState } from "react";
import { TypeScriptPlaygroundDataResponse, GithubPermalinkContext } from "../config/GithubPermalinkContext";
import { TypeScriptPlaygroundBase, TypeScriptPlaygroundBaseProps } from "./TypeScriptPlaygroundBase";
type TypeScriptPlaygroundProps = Omit<TypeScriptPlaygroundBaseProps, "data"> & { playgroundUrl: string };
export function TypeScriptPlayground(props: TypeScriptPlaygroundProps) {
const { playgroundUrl } = props;
const [data, setData] = useState(null as null | TypeScriptPlaygroundDataResponse);
const { getTypeScriptPlaygroundFn, githubToken, onError } = useContext(GithubPermalinkContext);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
getTypeScriptPlaygroundFn(playgroundUrl, githubToken, onError).then((v) => {
setIsLoading(false);
setData(v);
})
}, [getTypeScriptPlaygroundFn, githubToken, onError, playgroundUrl])
if (isLoading) {
return null;
}
if (!data) {
throw new Error("Loading is complete, but no data was returned.")
}
return <TypeScriptPlaygroundBase data={data} {...props} />
}