Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda