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

376
Vistas
React + TypeScript: Passing components in an Array as props

I am looking for a solution in TypeScript React to pass multiple components in an array. I have declared interfaces and importing it inside my component. But it gives me an error as 'Type 'Element' has no properties in common with type 'IDataView''.

I have added code snippet to what steps i am following. I am not sure what am i missing in the below code.

My Parent Component:

    const DataViewContainer:React.FC = () => {
 return (
    <ViewCollection views={[<BarChart />, <LineChart />]} />
 )
}

Child Component :

interface IViewCollection {
 views: IDataView[]
}
interface IDataView {
 barChartView?: React.ReactNode;
 lineChartView?: React.ReactNode;
}

const ViewCollection = (views: IViewCollection): JSX.Element => {
 return (
    <Carousel>
       {views.map((cmp) => { return (cmp) }}
    </Carousel>
 )
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

According to your type, you suppose to pass an object. Notice the fixes of props, views and the usage inside ViewCollection component.

const DataViewContainer: React.FC = () => {
  return (
    <ViewCollection
      views={{ barChartView: <BarChart />, lineChartView: <LineChart /> }}
    />
  );
};

const ViewCollection = (props: IViewCollection): JSX.Element => {
  return (
    <Carousel>
      {props.views.barChartView}
      {props.views.lineChartView}
    </Carousel>
  );
};

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