Trying to make calculations while passing props and functions through different components REACTPass props to parent component in React.jsreact-router - pass props to handler componentWhat is the difference between state and props in React?Cannot display HTML stringWhat's the difference between “super()” and “super(props)” in React when using es6 classes?Passing a function down to a component through props - REACTHow to set component default props on React componentReact: Passing down props to functional componentsReact component initialize state from propsPassing down React Components dynamically through props?

Mimic lecturing on blackboard, facing audience

How do apertures which seem too large to physically fit work?

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?

Is there an injective, monotonically increasing, strictly concave function from the reals, to the reals?

Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset

Does the Linux kernel need a file system to run?

What are the advantages of simplicial model categories over non-simplicial ones?

Pre-mixing cryogenic fuels and using only one fuel tank

What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?

14 year old daughter buying thongs

How could a planet have erratic days?

What's the difference between releasing hormones and tropic hormones?

photorec photo recovery software not seeing my mounted filesystem - trying to use photorec to recover lost jpegs

Biological Blimps: Propulsion

I'm the sea and the sun

It grows, but water kills it

Limits and Infinite Integration by Parts

Creepy dinosaur pc game identification

Why should universal income be universal?

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

Keeping a ball lost forever

What does chmod -u do?

Angel of Condemnation - Exile creature with second ability

Why can Carol Danvers change her suit colours in the first place?



Trying to make calculations while passing props and functions through different components REACT


Pass props to parent component in React.jsreact-router - pass props to handler componentWhat is the difference between state and props in React?Cannot display HTML stringWhat's the difference between “super()” and “super(props)” in React when using es6 classes?Passing a function down to a component through props - REACTHow to set component default props on React componentReact: Passing down props to functional componentsReact component initialize state from propsPassing down React Components dynamically through props?













0















Just to start, I am a beginner in React so I am trying to get the hang of passing props and placing different functions in different components. I have been stuck on this all day trying to figure it out.



I have an app that allows me to add a list of clients by input. I also have a another component that allows me to choose one of the existing clients from a dropdown menu and create a 'new lesson' with them. This way I can log my lessons done with my clients. This all works perfectly... this is where I get stuck.



Everytime I add a new lesson, I want to take the duration of the lesson (in hours) and multiply that by the corresponding client's price. I then want to be able to display that profit and everytime I add a new lesson with a new profit, I want it all to add up to a totalProfit of all the lessons.



I have different components that I will post here so you can take a look, I'm trying to figure out how to do that calculation but I think I am not passing down props and using functions correctly. Thanks for the help!



this is App.js



import React, Component from 'react'
import Clients from './components/Clients'
import AddClient from './components/AddClient'
import NavBar from './components/NavBar'
import AddLesson from './components/AddLesson'
import CalculateIncome from './components/CalculateIncome'

class App extends Component
state =
clients : [
// id : null , name : '', price : null
],
lessons : [
// id: null, name: '', time: null, date :null
],


deleteClient = (id) =>
let clients = this.state.clients.filter(client =>
return client.id !== id
)
this.setState(
clients: clients
)


addClient = (newClient) =>
newClient.id = Math.random();
let clients = [...this.state.clients, newClient];
clients.sort((a, b) => a.name.localeCompare(b.name))
this.setState(
clients: clients,
)


addLesson = (newLesson) =>
newLesson.id = Math.random();
newLesson.date = Date();
let lessons = [...this.state.lessons, newLesson];
this.setState(
lessons: lessons,
)


render()
return (
<div className="App">
<NavBar/>
<Clients clients=this.state.clients deleteClient=this.deleteClient lessons=this.state.lessons/>
<AddClient addClient=this.addClient/>
<AddLesson addLesson=this.addLesson lessons=this.state.lessons clients=this.state.clients income=this.state.income />
<CalculateIncome lessons=this.state.lessons clients=this.state.clients/>
</div>
);



export default App;


Here is my addLesson.js



import React, Component from 'react'

class AddLesson extends Component
state =
id: null, name: null, time: null, date : null


handleChange = (e) =>
this.setState(
[e.target.id] : e.target.value,
)
console.log([e.target.id]);


handleSubmit = (e) =>
e.preventDefault();
this.props.addLesson(this.state);
e.target.reset();



render()
return (
<div className="text-center mt-5">
<h2>Add a lesson</h2>
<form onSubmit=this.handleSubmit>
<label htmlFor="name">Client Name: </label>
<select onChange=(e) => this.handleChange(e) id="name">
<option value=""></option>
this.props.clients.map(client =>
<option key=client.id value=client.name.value>
client.name
</option>
)
</select>
<br/>
<label htmlFor="time">Lesson Duration (in hours): </label>
<input type="text" id="time" onChange=this.handleChange/><br/>
<button className="btn btn-primary">Add Lesson</button>
</form>
</div>
)



export default AddLesson


Here is my clients.js



import React from 'react'

const Clients = (clients, deleteClient, lessons) =>
const clientList = clients.map(client =>
return (
<div className="container" key=client.id>
<ul className="clientInfo">
<li className="py-3">
<span className="name">Client Name: client.name</span>
<span className="price pl-3 pr-5">Client Price: client.price</span>
<button className="btn btn-danger" onClick=() => deleteClient(client.id)>X</button>
</li>
</ul>
</div>
)
)
const lessonList = lessons.map(lesson =>
return (
<div className="container" key=lesson.id>
<ul className="lessonInfo">
<li className="py-1">
<span className="name">Lesson Name: lesson.name</span>
<span className="price pl-3 pr-3">Lesson Time(in hours): lesson.time</span>
<span className="date">Lesson Added: lesson.date</span>
</li>
</ul>
</div>
)
)
return(
<div className="container text-center">
<h2>Here are your current clients...</h2>
clientList
<h2>Here is the list of lessons so far</h2>
lessonList
</div>
)


export default Clients


and lastly, here is the CalculateIncome.js that I am working on, should it even be class based?



import React, Component from 'react'

class CalculateIncome extends Component
state =
totalIncome:0


calculation = () =>
this.props.lessons.filter(lesson =>
this.props.clients.filter(client =>
if (client.name === lesson.name)
let price = client.price
let time = lesson.time
return(price, time)

return (
this.setState(
totalIncome : (price * time)
)
)
)
)


render()
return ( this.props.lessons.length ?
(this.state.totalIncome)
:
(<div className="text-center my-5">You are broke</div>)
)



export default CalculateIncome









share|improve this question






















  • Sorry if I put up too much code, just wanted to make sure everything was out there. Even if you can explain in english (not code) how I can place my components and functions and props to complete this calculation, it would be great help! thank you!

    – josephT
    Mar 7 at 6:33















0















Just to start, I am a beginner in React so I am trying to get the hang of passing props and placing different functions in different components. I have been stuck on this all day trying to figure it out.



I have an app that allows me to add a list of clients by input. I also have a another component that allows me to choose one of the existing clients from a dropdown menu and create a 'new lesson' with them. This way I can log my lessons done with my clients. This all works perfectly... this is where I get stuck.



Everytime I add a new lesson, I want to take the duration of the lesson (in hours) and multiply that by the corresponding client's price. I then want to be able to display that profit and everytime I add a new lesson with a new profit, I want it all to add up to a totalProfit of all the lessons.



I have different components that I will post here so you can take a look, I'm trying to figure out how to do that calculation but I think I am not passing down props and using functions correctly. Thanks for the help!



this is App.js



import React, Component from 'react'
import Clients from './components/Clients'
import AddClient from './components/AddClient'
import NavBar from './components/NavBar'
import AddLesson from './components/AddLesson'
import CalculateIncome from './components/CalculateIncome'

class App extends Component
state =
clients : [
// id : null , name : '', price : null
],
lessons : [
// id: null, name: '', time: null, date :null
],


deleteClient = (id) =>
let clients = this.state.clients.filter(client =>
return client.id !== id
)
this.setState(
clients: clients
)


addClient = (newClient) =>
newClient.id = Math.random();
let clients = [...this.state.clients, newClient];
clients.sort((a, b) => a.name.localeCompare(b.name))
this.setState(
clients: clients,
)


addLesson = (newLesson) =>
newLesson.id = Math.random();
newLesson.date = Date();
let lessons = [...this.state.lessons, newLesson];
this.setState(
lessons: lessons,
)


render()
return (
<div className="App">
<NavBar/>
<Clients clients=this.state.clients deleteClient=this.deleteClient lessons=this.state.lessons/>
<AddClient addClient=this.addClient/>
<AddLesson addLesson=this.addLesson lessons=this.state.lessons clients=this.state.clients income=this.state.income />
<CalculateIncome lessons=this.state.lessons clients=this.state.clients/>
</div>
);



export default App;


Here is my addLesson.js



import React, Component from 'react'

class AddLesson extends Component
state =
id: null, name: null, time: null, date : null


handleChange = (e) =>
this.setState(
[e.target.id] : e.target.value,
)
console.log([e.target.id]);


handleSubmit = (e) =>
e.preventDefault();
this.props.addLesson(this.state);
e.target.reset();



render()
return (
<div className="text-center mt-5">
<h2>Add a lesson</h2>
<form onSubmit=this.handleSubmit>
<label htmlFor="name">Client Name: </label>
<select onChange=(e) => this.handleChange(e) id="name">
<option value=""></option>
this.props.clients.map(client =>
<option key=client.id value=client.name.value>
client.name
</option>
)
</select>
<br/>
<label htmlFor="time">Lesson Duration (in hours): </label>
<input type="text" id="time" onChange=this.handleChange/><br/>
<button className="btn btn-primary">Add Lesson</button>
</form>
</div>
)



export default AddLesson


Here is my clients.js



import React from 'react'

const Clients = (clients, deleteClient, lessons) =>
const clientList = clients.map(client =>
return (
<div className="container" key=client.id>
<ul className="clientInfo">
<li className="py-3">
<span className="name">Client Name: client.name</span>
<span className="price pl-3 pr-5">Client Price: client.price</span>
<button className="btn btn-danger" onClick=() => deleteClient(client.id)>X</button>
</li>
</ul>
</div>
)
)
const lessonList = lessons.map(lesson =>
return (
<div className="container" key=lesson.id>
<ul className="lessonInfo">
<li className="py-1">
<span className="name">Lesson Name: lesson.name</span>
<span className="price pl-3 pr-3">Lesson Time(in hours): lesson.time</span>
<span className="date">Lesson Added: lesson.date</span>
</li>
</ul>
</div>
)
)
return(
<div className="container text-center">
<h2>Here are your current clients...</h2>
clientList
<h2>Here is the list of lessons so far</h2>
lessonList
</div>
)


export default Clients


and lastly, here is the CalculateIncome.js that I am working on, should it even be class based?



import React, Component from 'react'

class CalculateIncome extends Component
state =
totalIncome:0


calculation = () =>
this.props.lessons.filter(lesson =>
this.props.clients.filter(client =>
if (client.name === lesson.name)
let price = client.price
let time = lesson.time
return(price, time)

return (
this.setState(
totalIncome : (price * time)
)
)
)
)


render()
return ( this.props.lessons.length ?
(this.state.totalIncome)
:
(<div className="text-center my-5">You are broke</div>)
)



export default CalculateIncome









share|improve this question






















  • Sorry if I put up too much code, just wanted to make sure everything was out there. Even if you can explain in english (not code) how I can place my components and functions and props to complete this calculation, it would be great help! thank you!

    – josephT
    Mar 7 at 6:33













0












0








0








Just to start, I am a beginner in React so I am trying to get the hang of passing props and placing different functions in different components. I have been stuck on this all day trying to figure it out.



I have an app that allows me to add a list of clients by input. I also have a another component that allows me to choose one of the existing clients from a dropdown menu and create a 'new lesson' with them. This way I can log my lessons done with my clients. This all works perfectly... this is where I get stuck.



Everytime I add a new lesson, I want to take the duration of the lesson (in hours) and multiply that by the corresponding client's price. I then want to be able to display that profit and everytime I add a new lesson with a new profit, I want it all to add up to a totalProfit of all the lessons.



I have different components that I will post here so you can take a look, I'm trying to figure out how to do that calculation but I think I am not passing down props and using functions correctly. Thanks for the help!



this is App.js



import React, Component from 'react'
import Clients from './components/Clients'
import AddClient from './components/AddClient'
import NavBar from './components/NavBar'
import AddLesson from './components/AddLesson'
import CalculateIncome from './components/CalculateIncome'

class App extends Component
state =
clients : [
// id : null , name : '', price : null
],
lessons : [
// id: null, name: '', time: null, date :null
],


deleteClient = (id) =>
let clients = this.state.clients.filter(client =>
return client.id !== id
)
this.setState(
clients: clients
)


addClient = (newClient) =>
newClient.id = Math.random();
let clients = [...this.state.clients, newClient];
clients.sort((a, b) => a.name.localeCompare(b.name))
this.setState(
clients: clients,
)


addLesson = (newLesson) =>
newLesson.id = Math.random();
newLesson.date = Date();
let lessons = [...this.state.lessons, newLesson];
this.setState(
lessons: lessons,
)


render()
return (
<div className="App">
<NavBar/>
<Clients clients=this.state.clients deleteClient=this.deleteClient lessons=this.state.lessons/>
<AddClient addClient=this.addClient/>
<AddLesson addLesson=this.addLesson lessons=this.state.lessons clients=this.state.clients income=this.state.income />
<CalculateIncome lessons=this.state.lessons clients=this.state.clients/>
</div>
);



export default App;


Here is my addLesson.js



import React, Component from 'react'

class AddLesson extends Component
state =
id: null, name: null, time: null, date : null


handleChange = (e) =>
this.setState(
[e.target.id] : e.target.value,
)
console.log([e.target.id]);


handleSubmit = (e) =>
e.preventDefault();
this.props.addLesson(this.state);
e.target.reset();



render()
return (
<div className="text-center mt-5">
<h2>Add a lesson</h2>
<form onSubmit=this.handleSubmit>
<label htmlFor="name">Client Name: </label>
<select onChange=(e) => this.handleChange(e) id="name">
<option value=""></option>
this.props.clients.map(client =>
<option key=client.id value=client.name.value>
client.name
</option>
)
</select>
<br/>
<label htmlFor="time">Lesson Duration (in hours): </label>
<input type="text" id="time" onChange=this.handleChange/><br/>
<button className="btn btn-primary">Add Lesson</button>
</form>
</div>
)



export default AddLesson


Here is my clients.js



import React from 'react'

const Clients = (clients, deleteClient, lessons) =>
const clientList = clients.map(client =>
return (
<div className="container" key=client.id>
<ul className="clientInfo">
<li className="py-3">
<span className="name">Client Name: client.name</span>
<span className="price pl-3 pr-5">Client Price: client.price</span>
<button className="btn btn-danger" onClick=() => deleteClient(client.id)>X</button>
</li>
</ul>
</div>
)
)
const lessonList = lessons.map(lesson =>
return (
<div className="container" key=lesson.id>
<ul className="lessonInfo">
<li className="py-1">
<span className="name">Lesson Name: lesson.name</span>
<span className="price pl-3 pr-3">Lesson Time(in hours): lesson.time</span>
<span className="date">Lesson Added: lesson.date</span>
</li>
</ul>
</div>
)
)
return(
<div className="container text-center">
<h2>Here are your current clients...</h2>
clientList
<h2>Here is the list of lessons so far</h2>
lessonList
</div>
)


export default Clients


and lastly, here is the CalculateIncome.js that I am working on, should it even be class based?



import React, Component from 'react'

class CalculateIncome extends Component
state =
totalIncome:0


calculation = () =>
this.props.lessons.filter(lesson =>
this.props.clients.filter(client =>
if (client.name === lesson.name)
let price = client.price
let time = lesson.time
return(price, time)

return (
this.setState(
totalIncome : (price * time)
)
)
)
)


render()
return ( this.props.lessons.length ?
(this.state.totalIncome)
:
(<div className="text-center my-5">You are broke</div>)
)



export default CalculateIncome









share|improve this question














Just to start, I am a beginner in React so I am trying to get the hang of passing props and placing different functions in different components. I have been stuck on this all day trying to figure it out.



I have an app that allows me to add a list of clients by input. I also have a another component that allows me to choose one of the existing clients from a dropdown menu and create a 'new lesson' with them. This way I can log my lessons done with my clients. This all works perfectly... this is where I get stuck.



Everytime I add a new lesson, I want to take the duration of the lesson (in hours) and multiply that by the corresponding client's price. I then want to be able to display that profit and everytime I add a new lesson with a new profit, I want it all to add up to a totalProfit of all the lessons.



I have different components that I will post here so you can take a look, I'm trying to figure out how to do that calculation but I think I am not passing down props and using functions correctly. Thanks for the help!



this is App.js



import React, Component from 'react'
import Clients from './components/Clients'
import AddClient from './components/AddClient'
import NavBar from './components/NavBar'
import AddLesson from './components/AddLesson'
import CalculateIncome from './components/CalculateIncome'

class App extends Component
state =
clients : [
// id : null , name : '', price : null
],
lessons : [
// id: null, name: '', time: null, date :null
],


deleteClient = (id) =>
let clients = this.state.clients.filter(client =>
return client.id !== id
)
this.setState(
clients: clients
)


addClient = (newClient) =>
newClient.id = Math.random();
let clients = [...this.state.clients, newClient];
clients.sort((a, b) => a.name.localeCompare(b.name))
this.setState(
clients: clients,
)


addLesson = (newLesson) =>
newLesson.id = Math.random();
newLesson.date = Date();
let lessons = [...this.state.lessons, newLesson];
this.setState(
lessons: lessons,
)


render()
return (
<div className="App">
<NavBar/>
<Clients clients=this.state.clients deleteClient=this.deleteClient lessons=this.state.lessons/>
<AddClient addClient=this.addClient/>
<AddLesson addLesson=this.addLesson lessons=this.state.lessons clients=this.state.clients income=this.state.income />
<CalculateIncome lessons=this.state.lessons clients=this.state.clients/>
</div>
);



export default App;


Here is my addLesson.js



import React, Component from 'react'

class AddLesson extends Component
state =
id: null, name: null, time: null, date : null


handleChange = (e) =>
this.setState(
[e.target.id] : e.target.value,
)
console.log([e.target.id]);


handleSubmit = (e) =>
e.preventDefault();
this.props.addLesson(this.state);
e.target.reset();



render()
return (
<div className="text-center mt-5">
<h2>Add a lesson</h2>
<form onSubmit=this.handleSubmit>
<label htmlFor="name">Client Name: </label>
<select onChange=(e) => this.handleChange(e) id="name">
<option value=""></option>
this.props.clients.map(client =>
<option key=client.id value=client.name.value>
client.name
</option>
)
</select>
<br/>
<label htmlFor="time">Lesson Duration (in hours): </label>
<input type="text" id="time" onChange=this.handleChange/><br/>
<button className="btn btn-primary">Add Lesson</button>
</form>
</div>
)



export default AddLesson


Here is my clients.js



import React from 'react'

const Clients = (clients, deleteClient, lessons) =>
const clientList = clients.map(client =>
return (
<div className="container" key=client.id>
<ul className="clientInfo">
<li className="py-3">
<span className="name">Client Name: client.name</span>
<span className="price pl-3 pr-5">Client Price: client.price</span>
<button className="btn btn-danger" onClick=() => deleteClient(client.id)>X</button>
</li>
</ul>
</div>
)
)
const lessonList = lessons.map(lesson =>
return (
<div className="container" key=lesson.id>
<ul className="lessonInfo">
<li className="py-1">
<span className="name">Lesson Name: lesson.name</span>
<span className="price pl-3 pr-3">Lesson Time(in hours): lesson.time</span>
<span className="date">Lesson Added: lesson.date</span>
</li>
</ul>
</div>
)
)
return(
<div className="container text-center">
<h2>Here are your current clients...</h2>
clientList
<h2>Here is the list of lessons so far</h2>
lessonList
</div>
)


export default Clients


and lastly, here is the CalculateIncome.js that I am working on, should it even be class based?



import React, Component from 'react'

class CalculateIncome extends Component
state =
totalIncome:0


calculation = () =>
this.props.lessons.filter(lesson =>
this.props.clients.filter(client =>
if (client.name === lesson.name)
let price = client.price
let time = lesson.time
return(price, time)

return (
this.setState(
totalIncome : (price * time)
)
)
)
)


render()
return ( this.props.lessons.length ?
(this.state.totalIncome)
:
(<div className="text-center my-5">You are broke</div>)
)



export default CalculateIncome






html reactjs components jsx






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 6:32









josephTjosephT

165




165












  • Sorry if I put up too much code, just wanted to make sure everything was out there. Even if you can explain in english (not code) how I can place my components and functions and props to complete this calculation, it would be great help! thank you!

    – josephT
    Mar 7 at 6:33

















  • Sorry if I put up too much code, just wanted to make sure everything was out there. Even if you can explain in english (not code) how I can place my components and functions and props to complete this calculation, it would be great help! thank you!

    – josephT
    Mar 7 at 6:33
















Sorry if I put up too much code, just wanted to make sure everything was out there. Even if you can explain in english (not code) how I can place my components and functions and props to complete this calculation, it would be great help! thank you!

– josephT
Mar 7 at 6:33





Sorry if I put up too much code, just wanted to make sure everything was out there. Even if you can explain in english (not code) how I can place my components and functions and props to complete this calculation, it would be great help! thank you!

– josephT
Mar 7 at 6:33












1 Answer
1






active

oldest

votes


















0














I think the issue is the way you have pass state values from App.js to CalculateIncome.js. So try to pass those state values like this.



class App extends Components
constructor(props)
super(props)
this.state=
lessons: 'Any value 1'
clients: 'Any value 2'

this.passLessonValue=this.passLessonValue.bind(this)
this.passClientValue=this.passClientValue.bind(this)

passLessonValue()
return this.state.lessons

passClientValue()
return this.state.client


render()
return(
<Calculate passLesson=this.passLessonValue
passClient=this.passClientValue/>
)




You must write functions which returns state values. And after that just pass those functions to Calculator.js by using props.
I ll show u how to use those functions in Calculator.js



class Calculator extends Components
constructor(props)
super(props)
this.state=
lesson1: null
client1 null


this.setLessonValue=this.setLessonValue.bind(this)
this.setClientValue=this.setClientValue.bind(this)

async setLessonValue()
await const val=this.props.passLesson()
this.setState(
lesson1: val
)

async setClientValue()
await const val2=this.props.passClient
this.setState(
client1: val2
)




So inside Calculator.js you must set state values. After that u must call a function and inside that function assign the props which was sent from App.js to a variable "val".(cuz props returns state value)After that set the state value of Calculator.js using the variable "val"






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037432%2ftrying-to-make-calculations-while-passing-props-and-functions-through-different%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I think the issue is the way you have pass state values from App.js to CalculateIncome.js. So try to pass those state values like this.



    class App extends Components
    constructor(props)
    super(props)
    this.state=
    lessons: 'Any value 1'
    clients: 'Any value 2'

    this.passLessonValue=this.passLessonValue.bind(this)
    this.passClientValue=this.passClientValue.bind(this)

    passLessonValue()
    return this.state.lessons

    passClientValue()
    return this.state.client


    render()
    return(
    <Calculate passLesson=this.passLessonValue
    passClient=this.passClientValue/>
    )




    You must write functions which returns state values. And after that just pass those functions to Calculator.js by using props.
    I ll show u how to use those functions in Calculator.js



    class Calculator extends Components
    constructor(props)
    super(props)
    this.state=
    lesson1: null
    client1 null


    this.setLessonValue=this.setLessonValue.bind(this)
    this.setClientValue=this.setClientValue.bind(this)

    async setLessonValue()
    await const val=this.props.passLesson()
    this.setState(
    lesson1: val
    )

    async setClientValue()
    await const val2=this.props.passClient
    this.setState(
    client1: val2
    )




    So inside Calculator.js you must set state values. After that u must call a function and inside that function assign the props which was sent from App.js to a variable "val".(cuz props returns state value)After that set the state value of Calculator.js using the variable "val"






    share|improve this answer





























      0














      I think the issue is the way you have pass state values from App.js to CalculateIncome.js. So try to pass those state values like this.



      class App extends Components
      constructor(props)
      super(props)
      this.state=
      lessons: 'Any value 1'
      clients: 'Any value 2'

      this.passLessonValue=this.passLessonValue.bind(this)
      this.passClientValue=this.passClientValue.bind(this)

      passLessonValue()
      return this.state.lessons

      passClientValue()
      return this.state.client


      render()
      return(
      <Calculate passLesson=this.passLessonValue
      passClient=this.passClientValue/>
      )




      You must write functions which returns state values. And after that just pass those functions to Calculator.js by using props.
      I ll show u how to use those functions in Calculator.js



      class Calculator extends Components
      constructor(props)
      super(props)
      this.state=
      lesson1: null
      client1 null


      this.setLessonValue=this.setLessonValue.bind(this)
      this.setClientValue=this.setClientValue.bind(this)

      async setLessonValue()
      await const val=this.props.passLesson()
      this.setState(
      lesson1: val
      )

      async setClientValue()
      await const val2=this.props.passClient
      this.setState(
      client1: val2
      )




      So inside Calculator.js you must set state values. After that u must call a function and inside that function assign the props which was sent from App.js to a variable "val".(cuz props returns state value)After that set the state value of Calculator.js using the variable "val"






      share|improve this answer



























        0












        0








        0







        I think the issue is the way you have pass state values from App.js to CalculateIncome.js. So try to pass those state values like this.



        class App extends Components
        constructor(props)
        super(props)
        this.state=
        lessons: 'Any value 1'
        clients: 'Any value 2'

        this.passLessonValue=this.passLessonValue.bind(this)
        this.passClientValue=this.passClientValue.bind(this)

        passLessonValue()
        return this.state.lessons

        passClientValue()
        return this.state.client


        render()
        return(
        <Calculate passLesson=this.passLessonValue
        passClient=this.passClientValue/>
        )




        You must write functions which returns state values. And after that just pass those functions to Calculator.js by using props.
        I ll show u how to use those functions in Calculator.js



        class Calculator extends Components
        constructor(props)
        super(props)
        this.state=
        lesson1: null
        client1 null


        this.setLessonValue=this.setLessonValue.bind(this)
        this.setClientValue=this.setClientValue.bind(this)

        async setLessonValue()
        await const val=this.props.passLesson()
        this.setState(
        lesson1: val
        )

        async setClientValue()
        await const val2=this.props.passClient
        this.setState(
        client1: val2
        )




        So inside Calculator.js you must set state values. After that u must call a function and inside that function assign the props which was sent from App.js to a variable "val".(cuz props returns state value)After that set the state value of Calculator.js using the variable "val"






        share|improve this answer















        I think the issue is the way you have pass state values from App.js to CalculateIncome.js. So try to pass those state values like this.



        class App extends Components
        constructor(props)
        super(props)
        this.state=
        lessons: 'Any value 1'
        clients: 'Any value 2'

        this.passLessonValue=this.passLessonValue.bind(this)
        this.passClientValue=this.passClientValue.bind(this)

        passLessonValue()
        return this.state.lessons

        passClientValue()
        return this.state.client


        render()
        return(
        <Calculate passLesson=this.passLessonValue
        passClient=this.passClientValue/>
        )




        You must write functions which returns state values. And after that just pass those functions to Calculator.js by using props.
        I ll show u how to use those functions in Calculator.js



        class Calculator extends Components
        constructor(props)
        super(props)
        this.state=
        lesson1: null
        client1 null


        this.setLessonValue=this.setLessonValue.bind(this)
        this.setClientValue=this.setClientValue.bind(this)

        async setLessonValue()
        await const val=this.props.passLesson()
        this.setState(
        lesson1: val
        )

        async setClientValue()
        await const val2=this.props.passClient
        this.setState(
        client1: val2
        )




        So inside Calculator.js you must set state values. After that u must call a function and inside that function assign the props which was sent from App.js to a variable "val".(cuz props returns state value)After that set the state value of Calculator.js using the variable "val"







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 7 at 9:54

























        answered Mar 7 at 9:30









        Sanu JaySanu Jay

        13




        13





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037432%2ftrying-to-make-calculations-while-passing-props-and-functions-through-different%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved