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

211
Visualizações
Next.js, loading a library client side, the component is re rendered twice and multiple times as the parent component state changes

I'm loading this library emoji-mart client side because it requires window object and then returning a component, while calling, the component is rendered twice to start with and then multiple times as parent component state changes.

function EmojiPicker(props = {}) {
  const ref = useRef()

  // loading the emojiMart lib clientside coz it requires 
  // window object
  useEffect(() => {
    import('emoji-mart').then((EmojiMart) => {
      new EmojiMart.Picker({ ...props, data, ref })
    })
  }, [])

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

function Feed = () => {
  
  const[value, setValue] = useState('')

  return (    
  ...
  ...
  <input value={value} onChange={handleChange}/>
  ...
  ...
  
  <EmojiPicker/>   
  /* EmojiPicker rendered twice and again and again whenever 
  input state changes */
    
  )
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use React.memo to prevent unnecessary rerendering. It's easy to use, only you have to do is to wrap the component.

import React from 'react';

const EmojiPicker = React.memo(() => {
 ...
 return <div ref={ref}></div>
})
 

React.memo prevent rerender if there's no changes in props variables.

about 4 years ago · Juan Pablo Isaza Relatório
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