import { useEffect, createRef } from 'react' 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' import { GetServerSidePropsContext } from 'next' import { getData } from './api/get/[id]' 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, codeRef]) return (
fastbin
fastbin
router.push('/')} >
{ lines.map((_line, index) =>
 {index + 1} 
) }
                    
                    
                
) } export const getServerSideProps = async (context: GetServerSidePropsContext) => { const id = context.params?.id if (!id) return { redirect: { destination: '/', permanent: false, } } let data = (await getData(id.toString())).data if (!data) { return { redirect: { destination: '/', permanent: false, } } } return { props: { code: data.code, } } } export default Viewer