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

134
Visualizações
Why my React child component is not re-rendering?

I'm developing a console-like web application. When the user inputs something, a component is appended in a childrens element that is a prop of a <ConsoleOutput> component; for example, when the user inputs 'chatrooms list', a <ChatroomList> component is created:

const [childrens, setChildrens] = useState([]);

/* Switch that analizes input */
case 'chatrooms list':
        setChildrens(childrens => {
          return (
            [...childrens,
            <ChatroomList chatrooms={chatrooms} />]
          );
        });
        break;

So in the App I return this:

return (
    <div className='container-fluid'>
      <Header />
      <ConsoleOutput childrens={childrens} />
      <CommandInput onSubmit={processCommand} />
    </div>
  );

This is working great, the components get appended properly on input and reflected on screen (is re-rendering on change); the thing is, this childrens aren't getting re-rendering on change, for example, <ChatroomList> that takes a chatrooms prop.

This prop is getting updated constantly with an useEffect hook:

  useEffect(() => {
    const getChatrooms = async () => {
      const response = await fetchChatrooms();
      if (response.success) {
        const serverChatrooms = response.chatrooms;
        setChatrooms(serverChatrooms);
      }
    }

    getChatrooms();
  }, [chatrooms]);

So if the user inputs chatrooms list, this <ChatroomList> component is created and displayed on screen, but if the chatrooms prop changes, I have to create again the component or reload the page to see the changes.

I suspect that this is because this component is a child component of <ConsoleOutput>, but I'm not sure.

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