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

204
Visualizações
Material UI portal component vanishes after page refresh in next.js

I use Next.js and Material UI. I need to render an element in another place, because of the Swiper library that I use.

For this purpose, I'm using Material UI's <Portal> component and here's my code:

import { useRef } from 'react'
import Portal from '@mui/material/Portal';

//more code here

const container = useRef(null);

//more code here

<div ref={container}></div>

//more code here

<Swiper
    spaceBetween={20}
    slidesPerView={1}
>
    <Portal container={container.current}>
        <SwiperButton></SwiperButton>
    </Portal>
    {
        ads.map(ad => <SwiperSlide key={ad.imageUrl}>
            <div>{ad.title}</div>
        </SwiperSlide>
        )}
</Swiper>

This code works just fine for the first load of my web page. But as soon as I refresh the web page, it vanishes and disappears completely and there is no error whatsoever in the console.

And no matter what I do, it won't come back. Ctrl+F5 does not work and stopping and destroying and recreating my container does not work.

The only way to make it work is to comment that part of code, load the page and uncomment it again.

Why is it so, and how can I fix this problem?

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