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

582
Visualizações
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 à 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