Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
Not able to pass Array into another component in react

response is an array returned by my API. I am passing this variable to another component to create table in UI.

const [response, setResponse]= useState([]);
  useEffect(() => {
    (
      async () => {
        await axios.get('http://localhost:3000/api/certificates').
        then(response=>{
            setResponse(response.data);
            setFlag(true);
        })   
     }
    )()
  }, []);

I am using this response to another component to create table.

const ResultTable = (response: any[]) => {
-----------code------
----------code------
}

I am calling component like below.

                    <tbody> 
                      <ResultTable response={response}/>  //this line giving error
                    </tbody>

enter image description here

what mistake I am doing?

if I do like below

({response}: any[]) 

it does not recognize response variable. my file is .tsx enter image description here

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Your ResultTable component should looks something like this,

const ResultTable = ({ response }) => {
-----------code------
----------code------
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try updating the destructuring at ResultTable as:

const ResultTable = ({response}: any[]) => {
-----------code------
----------code------
}

Also, update the state initialization as

const [response, setResponse]= useState<any[]>([]);
about 4 years ago · Juan Pablo Isaza Denunciar

0

I just learned this too but empty array is automatically infered to the type "never". I believe if you change your useState hook to this:

 useState([] as any);

it will work.

And also change this one to const ResultTable = ({ response })

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda