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

167
Vistas
Props are not passing from parent to child components in React Functional component

Hi developers I'm just a beginner in React.js. I tried to print props by passing from parent to child.

This is app.js file

    import React from "react";
    import Hooks from "./components/ReactHooks1";
    import Hooks2 from "./components/ReactHooks2";
    
    const App = () => {
        return (
            <div>
            <h1>
                Welcome to React App
            </h1>
            <Hooks2 title2={"Welcome"}/>
            </div>
    
        )
    }
    
    export default App

This is child component file

import React from 'react';


const Hooks2 = (props) => {
    console.log(props);
}


export default Hooks2;

I just try to print props but it shows an empty object. what am I doing wrong please help me on this

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

0

You should return something or null to parent component from child, when you're using it in parent component. This will solve your problem

export const Hooks2 = (props) => {
    console.log(props);
    return <></>;
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

@Rasith

Not sure why would you want to do this, but if you're trying to pass a child component that would print something to the console. In this case you need to destructure the component's props. Here's an article about it from MDN.

This is how I would do it:

const CustomComponent = ({title}) => {
  console.log(title)
}

const App = () => {
  return (
    <>
      <h1>Hello World</h1>
      <CustomComponent title={"Welcome"}/>
    </>
  );
};

For the title to be printed to the console, no need to add a return statement to the child component. Again, not sure why you would do this, but there you go.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Well trying to console.log title certainly would not work because what you are passing is called title2. Also your child component is not returning anything.

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