import { useRef, useEffect, useState } from 'react' import type { NextPage } 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'; const Viewer: NextPage = () => { const codeRef = useRef(null) const [code, setCode] = useState("") const router = useRouter() const { id } = router.query useEffect(() => { fetch(`/api/get/${id}`) .then(res => res.json()) .then((data) => setCode(data.code)) .catch(() => router.push('/')) }, []) 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('/')} >note_add
{ lines.map((line, index) =>
 {index + 1} 
) }
                    
                    
                
) } export async function getServerSideProps() { return { props: {}, } } export default Viewer