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

149
Vistas
How to set Interfaces dynamically to receive props in a shared component?

I have three different interfaces which are being received as props types by three different components, the thing is, the three components are identical and I'd like to use only one component, but dynamically, with their values based on the received props.

const UsersOverview: React.FC<{users: Interface[]}> = props => {...}

In React with JS I would just set a props and receive the value as props.anything, but with typescript I'd like to know how to set the interface dynamically:

I have something like that:

Interface 1:

export default interface Interface1{
    id: number,
    name: string,
    companyId: number
}

Interface 2:

export default interface Interface2 {
    id: number,
    email: string,
    name: string,
    unitId: number,
    companyId: number
}

Interface 3:

export default interface Interface3 {
    id: number | null,
    name: string | null
}

My child component is like this (I'm using Interface3, but I'd like to set this dynamically):

import React from 'react'

import Interface1 from '/models/Interface3'


const CompanyOverview: React.FC<{company: Interface3}> = props => {
    let [companyName, setCompanyName] = React.useState<string | null>('')

    React.useEffect(() => {
        setCompanyName(props.company.name)        
    }, [props.company])

    return (
        <div>
           <p>Contratante: {companyName}</p>
        </div>
    )
}

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