• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

61
Vistas
Access props of imported component in React

How could I pass/access the props of an imported component? This example component comes from a third-party library, so I'm not sure how I'd go about getting its props

import { Example } from './comps' 
    
const App = () => {
  return (
    <Example />
  );
  console.log(Example.props) //this returns undefined 
}

export default App;
over 2 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You cannot access props of a child Component from parent Component in that way.
Moreover:

const App = () => {
  return ( // return will finish the function, so the console.log below doesn't make any sense.
    <Example />
  );
  console.log(Example.props) //this returns undefined 
}

In your example, props is the things passed from App, so you can pass/access directly from App:

const App = () => {
  const [value, setValue] = useState(0);

  return (
    <Example number={value} setNumber={setValue} />
  );
}
over 2 years ago · Santiago Trujillo 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda