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

126
Visualizações
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 Respostas
Responde à pergunta

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