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

135
Views
passing props from parent to children in react

I want to pass props from parent to several children components , but eventually I get the error of Cannot read properties of undefined (reading 'props') App.js :

  render() {
    const {currentUser} = this.props
    return (
      <div id="App" className='loader'>
        <BrowserRouter>
            <Routes>
              <Route path='women' element={<Women currentUser={currentUser} />} />

Women.js:

  render() {
    const { isLoading } = this.state;
    if (isLoading) {
        return null;
    }
    const {currentUser} = this.props

    return (
        <div>
            <div className='container mx-auto'>
                <HomeHeaderW style={{ backgroundColor: "#fff2e0" }} currentUser={currentUser} />

HomeHeaderW.js :

function HomeHeaderW() {
   const {currentUser} = this.props
   const [isLogged, setLogged] = useState(false);
   useEffect(() => {
     if(currentUser) {
         setLogged(true)
     }
   });

I don't know why I get the undefined error , do you have an idea about this ? Or Am I doing it in the wrong way

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

HomeHeaderW is a function-based component (Women and App are class-based components), you cannot get props from this.props

You should pass your props on the params

function HomeHeaderW(props) {
  const {
    currentUser
  } = props;

  const [isLogged, setLogged] = useState(false);
  useEffect(() => {
    if (currentUser) {
      setLogged(true)
    }
  });

You can check this document for a better understanding

about 4 years ago · Juan Pablo Isaza 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!