Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
Javascript event listener in ReactJS with NextJS causes dynamically imported with no SSR module not to load

ReactJS and NextJS newbie here would appreciate any advice on below issue! Thanks!

The stack:

  • Node v16.6.1
  • React v17.0.2
  • Next.js v10.0.4

I am implementing a carousel, and--since carousel will need client-side javascript--am using next/dynamic to implement a dynamic component with no SSR. This works fine, but when I add a javascript event listener to the dynamic module, the module stops being rendered.

Debugging Next in Chrome DevTools shows no errors or warning when compiling the page. I couldn't find a reference to any additional compile information being available in Next documentation.

Parent module:

import react from 'react';
import dynamic from 'next/dynamic'


const DynamicComponentWithNoSSR = dynamic(
    () => import('../components/shared/dynamicTestComponent'),
    { ssr: false }
  )

const TestEmbedDynamicComponent: React.FC = () => {

    return (
      <div>
      <div>this is text above dynamic component</div>
        <DynamicComponentWithNoSSR/>
        <div>this is text below dynamic component</div>
        </div>
    )}

export default TestEmbedDynamicComponent

Dynamic module:

const selectedButton = document.querySelector(".selectMe");
//selectedButton.addEventListener("click", e => {alert("dynamic module loaded!");});

const DynamicTestComponent: React.FC = () => {

    return (
        <div className="">lorem ipsum
        <button className="selectMe">clickMe!</button>
        </div>
        
    )}

export default DynamicTestComponent

Result:

result with no listener

And if I uncomment the line where the listener is added:

result when listener added

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda