Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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

over 4 years ago · Santiago Trujillo
3 answers
Answer question

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 <></>;
}
over 4 years ago · Santiago Trujillo Report

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.

over 4 years ago · Santiago Trujillo Report

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!