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

125
Views
Can I pass props to a React Component from a general function?
   import B from './B.js'; 
   const Test = () => {
      
      async function getResults() {
        await axios
          .get(`http://localhost:2000/?url=${link}`)
          .then((response) => {
            <B data={response.data} />
          });
      }
      return (
        <>
          <div> 
           <button onClick={getResults}> Click </button>
         </div>
        </>
          )

I was trying to pass the axios data as props to my component B. But in console I got undefined value. How to solve this issue. Should I pass the props inside the return area of the Test Component only?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to use useState to store data

import B from './B.js';
import { useState } from 'react'
const Test = () => {
  const [data, setData] = useState({})
  async function getResults () {
    await axios
      .get(`http://localhost:2000/?url=${link}`)
      .then((response) => {
        setData(response.data)
      });
  }
  return (
    <>
      <div>
        <button onClick={getResults}> Click </button>
        <B data={data} />

      </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!