-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithubPermalink.tsx
More file actions
33 lines (24 loc) · 1.02 KB
/
GithubPermalink.tsx
File metadata and controls
33 lines (24 loc) · 1.02 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
31
"use client"
import { useContext, useEffect, useState } from "react";
import { GithubPermalinkDataResponse, GithubPermalinkContext } from "../config/GithubPermalinkContext";
import { GithubPermalinkBase, GithubPermalinkBaseProps } from "./GithubPermalinkBase";
type GithubPermalinkProps = Omit<GithubPermalinkBaseProps, "data"> & { permalink: string };
export function GithubPermalink(props: GithubPermalinkProps) {
const { permalink } = props;
const [data, setData] = useState(null as null | GithubPermalinkDataResponse)
const { getDataFn, githubToken, onError } = useContext(GithubPermalinkContext);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
getDataFn(permalink, githubToken, onError).then((v) => {
setIsLoading(false);
setData(v);
})
}, [getDataFn, githubToken, onError, permalink])
if (isLoading) {
return null;
}
if (!data) {
throw new Error("Loading is complete, but no data was returned.")
}
return <GithubPermalinkBase data={data} {...props} />
}