Trying to pass a function back to App.js and getting stuck REACTReact js onClick can't pass value to methodHow get value datapicker in react toobox custom?Get version number from package.json in React Redux (create-react-app)React className changes but CSS style do notFunctions and re-renders in React ContextHow to add Material-ui App Bar to class component?Can you pass this as an argument to a renderless component in React?Why does createRef() returns current: null?React Router structuring - passing functionsTrying to make calculations while passing props and functions through different components REACT
Are hand made posters acceptable in Academia?
Why is "la Gestapo" feminine?
Should a narrator ever describe things based on a character's view instead of facts?
Why would five hundred and five same as one?
What 1968 Moog synthesizer was used in the Movie Apollo 11?
Strange behavior in TikZ draw command
Showing mass murder in a kid's book
Error in master's thesis, I do not know what to do
Capacitor electron flow
Does capillary rise violate hydrostatic paradox?
Do I have to take mana from my deck or hand when tapping this card?
Started in 1987 vs. Starting in 1987
"Marked down as someone wanting to sell shares." What does that mean?
Mortal danger in mid-grade literature
What is the meaning of "You've never met a graph you didn't like?"
Taking the numerator and the denominator
Why doesn't Gödel's incompleteness theorem apply to false statements?
Friend wants my recommendation but I don't want to give it to him
Why didn’t Eve recognize the little cockroach as a living organism?
Derivative of an interpolated function
Make a Bowl of Alphabet Soup
Why can't I get pgrep output right to variable on bash script?
Mac Mini (2018) 10Gb Port Compatibility
A seasonal riddle
Trying to pass a function back to App.js and getting stuck REACT
React js onClick can't pass value to methodHow get value datapicker in react toobox custom?Get version number from package.json in React Redux (create-react-app)React className changes but CSS style do notFunctions and re-renders in React ContextHow to add Material-ui App Bar to class component?Can you pass this as an argument to a renderless component in React?Why does createRef() returns current: null?React Router structuring - passing functionsTrying to make calculations while passing props and functions through different components REACT
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.
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;
This is CalculateIncome.js
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
If you need to see any other components including AddLesson.js and Clients.js please let me know I will post it up as well.
html reactjs components jsx
add a comment |
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.
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;
This is CalculateIncome.js
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
If you need to see any other components including AddLesson.js and Clients.js please let me know I will post it up as well.
html reactjs components jsx
Excuse me but what exactly is your question ?
– Coder949
Mar 7 at 20:38
I have some components: App.js, Clients.js, AddClient.js AddLesson.js, and CalculateIncome.js. I am able to add clients and use those existing clients to add a lesson corresponding to each client. Each lesson has a time duration and each client has a price per hour. I want to create a function that will multiply (lesson.time * client.price) so I can know my income. My question is where would I put this function, would I put it straight in App.js or in AddLesson.js or would it just be its own calculation in CalculateIncome.js and how would I pass these properties up and down the components?
– josephT
Mar 7 at 20:43
add a comment |
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.
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;
This is CalculateIncome.js
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
If you need to see any other components including AddLesson.js and Clients.js please let me know I will post it up as well.
html reactjs components jsx
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.
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;
This is CalculateIncome.js
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
If you need to see any other components including AddLesson.js and Clients.js please let me know I will post it up as well.
html reactjs components jsx
html reactjs components jsx
asked Mar 7 at 20:17
josephTjosephT
165
165
Excuse me but what exactly is your question ?
– Coder949
Mar 7 at 20:38
I have some components: App.js, Clients.js, AddClient.js AddLesson.js, and CalculateIncome.js. I am able to add clients and use those existing clients to add a lesson corresponding to each client. Each lesson has a time duration and each client has a price per hour. I want to create a function that will multiply (lesson.time * client.price) so I can know my income. My question is where would I put this function, would I put it straight in App.js or in AddLesson.js or would it just be its own calculation in CalculateIncome.js and how would I pass these properties up and down the components?
– josephT
Mar 7 at 20:43
add a comment |
Excuse me but what exactly is your question ?
– Coder949
Mar 7 at 20:38
I have some components: App.js, Clients.js, AddClient.js AddLesson.js, and CalculateIncome.js. I am able to add clients and use those existing clients to add a lesson corresponding to each client. Each lesson has a time duration and each client has a price per hour. I want to create a function that will multiply (lesson.time * client.price) so I can know my income. My question is where would I put this function, would I put it straight in App.js or in AddLesson.js or would it just be its own calculation in CalculateIncome.js and how would I pass these properties up and down the components?
– josephT
Mar 7 at 20:43
Excuse me but what exactly is your question ?
– Coder949
Mar 7 at 20:38
Excuse me but what exactly is your question ?
– Coder949
Mar 7 at 20:38
I have some components: App.js, Clients.js, AddClient.js AddLesson.js, and CalculateIncome.js. I am able to add clients and use those existing clients to add a lesson corresponding to each client. Each lesson has a time duration and each client has a price per hour. I want to create a function that will multiply (lesson.time * client.price) so I can know my income. My question is where would I put this function, would I put it straight in App.js or in AddLesson.js or would it just be its own calculation in CalculateIncome.js and how would I pass these properties up and down the components?
– josephT
Mar 7 at 20:43
I have some components: App.js, Clients.js, AddClient.js AddLesson.js, and CalculateIncome.js. I am able to add clients and use those existing clients to add a lesson corresponding to each client. Each lesson has a time duration and each client has a price per hour. I want to create a function that will multiply (lesson.time * client.price) so I can know my income. My question is where would I put this function, would I put it straight in App.js or in AddLesson.js or would it just be its own calculation in CalculateIncome.js and how would I pass these properties up and down the components?
– josephT
Mar 7 at 20:43
add a comment |
0
active
oldest
votes
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052140%2ftrying-to-pass-a-function-back-to-app-js-and-getting-stuck-react%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052140%2ftrying-to-pass-a-function-back-to-app-js-and-getting-stuck-react%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Excuse me but what exactly is your question ?
– Coder949
Mar 7 at 20:38
I have some components: App.js, Clients.js, AddClient.js AddLesson.js, and CalculateIncome.js. I am able to add clients and use those existing clients to add a lesson corresponding to each client. Each lesson has a time duration and each client has a price per hour. I want to create a function that will multiply (lesson.time * client.price) so I can know my income. My question is where would I put this function, would I put it straight in App.js or in AddLesson.js or would it just be its own calculation in CalculateIncome.js and how would I pass these properties up and down the components?
– josephT
Mar 7 at 20:43