Closed tianxiuali closed 1 year ago
You can import the library dynamically on NextJS.
import { useEffect } from 'react'
import Highlighter from "web-highlighter"
const Highlight = () => {
useEffect(() => {
let highlighter = new Highlighter()
highlighter.run()
return () => highlighter.dispose()
}, [])
return (
<></>
)
}
export default Highlight
import Navbar from './navbar'
import Footer from './footer'
import dynamic from 'next/dynamic'
const Highlight = dynamic(() => import('./Highlight'), { ssr: false })
export default function Layout({ children }) {
return (
<>
<Navbar />
<main>{children}</main>
<Highlight />
<Footer />
</>
)
}
You can import the library dynamically on NextJS.
import { useEffect } from 'react' import Highlighter from "web-highlighter" const Highlight = () => { useEffect(() => { let highlighter = new Highlighter() highlighter.run() return () => highlighter.dispose() }, []) return ( <></> ) } export default Highlight
import Navbar from './navbar' import Footer from './footer' import dynamic from 'next/dynamic' const Highlight = dynamic(() => import('./Highlight'), { ssr: false }) export default function Layout({ children }) { return ( <> <Navbar /> <main>{children}</main> <Highlight /> <Footer /> </> ) }
Oh cooool! It works! Thank you so much!
在Next.js项目中import Highlighter from 'web-highlighter'就会报错