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

218
Visualizações
How do I pass a component reference to another component?

I have two components Grid and Filter, I need to link these two components. That is, pass the Grid link to the Filter. The link to the Grid in the Filter is needed in order to be able to tell the filter which grid to work with.

App.js:

  return (
    <div>
      <Grid ref={ref1}.../>
      <Filter gridRef={ref1}.../>
      <.../>
    </div>
  )

What do I need to do?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You will have to make the grid a frowardRef component. Understand forwardRef components.

Next, create a ref (let say rfGrid) with useRef hook in the parent component. Pass rfGrid to the ref prop of the Grid component and pass rfGrid to the gridRef prop of the Filter component.

import React, { useRef } from 'react';

const Parent = () => {
    const rfGrid = useRef();

    return (
        <div>
            <Grid ref={rfGrid} />
            <Filter gridRef={rfGrid} />
        </div>
    );
};
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