From a99be0c1d86f8e3816b43693d12c286c37d3d702 Mon Sep 17 00:00:00 2001 From: Divyam Date: Tue, 3 Oct 2023 13:26:14 +0530 Subject: [PATCH] refactor index.tsx and [id].tsx --- pages/[id].tsx | 11 ++++------- pages/index.tsx | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pages/[id].tsx b/pages/[id].tsx index 15b8345..6890d62 100644 --- a/pages/[id].tsx +++ b/pages/[id].tsx @@ -8,23 +8,20 @@ import header_styles from '../styles/Header.module.css' import 'highlight.js/styles/atom-one-dark.css'; import NoteAdd from '@material-ui/icons/NoteAdd' -import { GetServerSideProps } from 'next' +import { GetServerSidePropsContext } from 'next' const Viewer = ({ code }: {code: string}) => { const codeRef = createRef(); - const router = useRouter() - const lines = code.split('\n'); - const html = hljs.highlightAuto(code); useEffect(() => { if (codeRef.current) codeRef.current.innerHTML = html.value; - }, [html]) + }, [html, codeRef]) return (
@@ -59,7 +56,7 @@ const Viewer = ({ code }: {code: string}) => { ) } -export const getServerSideProps = (async (context) => { +export const getServerSideProps = async (context: GetServerSidePropsContext) => { const id = context.params?.id // const setCode = (data) => {}; @@ -78,6 +75,6 @@ export const getServerSideProps = (async (context) => { code: data.code, } } -}) satisfies GetServerSideProps<{ code: string }> +} export default Viewer diff --git a/pages/index.tsx b/pages/index.tsx index 8435b1f..7391e41 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -24,7 +24,7 @@ const Home: NextPage = () => { }).then(res => res.json()) .then(({ id }) => router.push(`/${id}`)) .catch(() => router.push('/')) - }, []) + }, [router]) useEffect(() => { const listener = (event : KeyboardEvent) => {