Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!