import { useRef, useEffect, useState, createRef } from 'react' import type { InferGetServerSidePropsType, NextPage } from 'next' import { GetServerSideProps } from 'next' import Head from 'next/head' import { useRouter } from 'next/router' import hljs from 'highlight.js' import styles from '../styles/Viewer.module.css' import header_styles from '../styles/Header.module.css' import 'highlight.js/styles/atom-one-dark.css'; import NoteAdd from '@material-ui/icons/NoteAdd' 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]) return (
fastbin
fastbin
router.push('/')} >
{ lines.map((_line, index) =>
 {index + 1} 
) }
                    
                    
                
) } export const getServerSideProps = (async (context) => { const id = context.params?.id // const setCode = (data) => {}; const data = await fetch(`/api/get/${id}`).then(res => res.json()) if (!data.code) { return { redirect: { destination: '/', permanent: false, } } } return { props: { code: data.code, } } }) satisfies GetServerSideProps<{ code: string }> export default Viewer