简体   繁体   中英

Executing client-side DOM manipulation after static rendering in NextJS

I would like to render a Tripetto form in my NextJS static page. Unfortunately, the Tripetto library uses the "window" object, which is undefined with static rendering.

Is there a way to execute client-side Javascript after static rendering in NextJS to avoid this issue?

Many thanks!

window is not defined server side . You can import Tripetto by using next/dynamic import in this way :

import dynamic from 'next/dynamic'
const Tripetto = dynamic(()=> import('Tripetto'), {ssr: false})

Doing this next will load your lib client side and window will be defined

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM