I'm a beginner writing a React app with currently three components minus the root App (yes this is for an online course). The first two don't really matter, but for the third one, named Total, I need to return a sum of the exercises count which are defined as three constants, exercises1~3.
I've been taught how to sum props, but only as {props + props1 + props2...}, and I could do it as well, but it would not be good as the number of parts and exercises grow. I could reduce the values or write a helper function, but React works kinda different and I'm kinda lost as to how I could provide a good scalable solution for this.
//first two components hidden
const Total = (props) => {
return (
<>
<p>help here!!</p>
</>
)
}
const App = () => {
const course = "Half Stack app development"
const part1 = "Fundamentals of React"
const exercises1 = 10 //this one
const part2 = "Using props to pass data"
const exercises2 = 7 //this one
const part3 = "State of a component"
const exercises3 = 14 //and this one
return (
<div>
<Header name={course} />
<Content name={part1} exercises={exercises1} />
<Content name={part2} exercises={exercises2} />
<Content name={part3} exercises={exercises3} />
<Total exercises= help here!! />
</div>
)
}