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

124
Vistas
What causes the failure to pass props from parent to child in this React application?

I am working on a small React app. It has a list of buttons in a Buttons.js component.

Following this guide, I am trying to pass the value of the label attribute into the single button template like this:

In Buttons.js:

import './Buttons.css';
import Button from './Button';

const Buttons = (props) => {
 return (
  <ol class="buttons-container">
   <Button label="Clik 1" />
   <Button label="Clik 2" />
   <Button label="Clik 3" />
  </ol>
 );
};

export default Buttons;

In Button.js:

import './Button.css';

const Button = () => {
  return ( <li>{ this.props.label }</li> );
}

export default Button;

The problem

The code above shows no error in the console, but it does throw this in the browser's console:

Cannot read properties of undefined (reading 'props')
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The correct code is

import './Button.css';

const Button = (props) => {
  return ( <li>{ props.label }</li> );
}

export default Button;

You forgot to pass props and you were using this.props.label.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You're confusing Class Components and Function Components.

In a Function Component, like the one you, have props are passed as the first argument to the function.

const Button = (props) => {
    return ( <li>{props.label}</li> );
}

And commonly destructured:

const Button = ({label}) => {
    return ( <li>{label}</li> );
}

You would access props via this if you were writing a Class Component:

class Button extends React.Component {
    render() {
        return ( <li>{this.props.label}</li> );
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

First, your Button component is a functional component, so no need for this. Second, you need to define props in your button component;

const Button = (props) => {
  return ( <li>{ props.label }</li> );
}

export default Button;
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