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

107
Views
How to pass props from function component to class component in React?

I usually work with function components in React, however, my teammate used a class component, and now I am struggling with understanding how to pass props from my component to my teammate's one.

What I have (consider as MyFile.js):

  const [dataDB, setData] = useState([]);

  useEffect(() => { 
    getData();
  }, []);

  const getData = async() => {
    // some api fetching here
    .then(result => setData(result.data))
  };

  return (
    // here I am using my dataDB 
    // but I also want to pass it to another component
    <AnotherComponent dataDB={dataDB} />
  );

What my teammate has (consider as AnotherFile.js):

 const anotherData = {
   name: "Dummy Name" //dataDB.name should be here
 };
    
 export default class MainAnotherComponent extends React.PureComponent {
   state = {
     data: anotherData
   };

  render() {
    return (
        ...
        //recursion happens here, I guess
        <AnotherComponent
          data={this.state.data}/>
        ...
    );
  }
}

I am not sure how to pass dataDB from my functional component to the class one. As you could see, I tried to pass it like that:

<AnotherComponent dataDB={dataDB} />

But how can I access that dataDB within that AnotherComponent?

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