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

580
Vistas
When passing props to my component it consoles 'undefined'

I might be missing something, but after struggling a bit, I followed a tutorial showing the basics of props. My prop is passing, but all my variables are returning as undefined. Im trying to pass my calculations to a component to display the total.

My calculation component (IncomeAndexpenses.js)

import {useState, useEffect} from 'react';
import HeadSection from '../HeadSection';

const IncomeVals = () => { 
    
    const [TotIncome, settotIncome] = useState(0);
    const [totTaxBrackets ,settotTaxBrackets] = useState(0);
    const [AvValues ,setAvValues] = useState();

const Users= [{
    name: 'Johan Golden', salary: 60000
}, {
    name: 'Susan Golden', salary: 27000
}
]

const expenses= [{
    name: 'Johan Golden', salary: 60000
}, {
    name: 'Susan Golden', salary: 27000
}
]

useEffect(() => {

    let totalIcome = 0;
    let totalIcomeTax = 0;

    Users.forEach(element => {
        totalIcome += element.salary;
      });

    console.log(totalIcome);

    settotIncome(totalIcome);

    //taxBrackets
    totalIcome = totalIcome * 12;

    console.log(totalIcome);

}, []);

    return (
        <>
            <HeadSection name="josh" totalIncome = {TotIncome}/>
        </>

    )
}

export default IncomeVals;

And then displaying on this component (HeadSection)

import React from "react";

const HeadSection = (props) => {

    console.log(props.name);

    return (
        <div className='SectionOne'>
            <hr></hr>
            <div className='subSections'>
                <div className='subSection'><h3>Total Income</h3><br></br><h2>R{props.totalIncome}</h2></div>
                <div className='subSection'><h3>Total Expenses</h3><br></br><h2>R13 327</h2></div>
                <div className='subSection'><h3>Total Income after tax</h3><br></br><h2>R65 560</h2></div>
            </div>
            <hr></hr>
        </div> 
    )
}

export default HeadSection;

Any help would be much appreciated!

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