6.4: Props Answer 2
The below code represents one possible solution for the challenge. You may want to put these 3 methods between your constructor and render in your class component.
In addition to the methods built out above, you'll want to modify your function
props in each of the FunctionalComp
calls. I've also changed the values of the string
props to make sure it's clear to the user what each button will do. Here is a sample solution:
When this is set up, you should be able to toggle each button and see a change in the DOM. Below is a screen capture of what your DOM can look like when you've clicked every button once:
Take a second to evaluate what your code is doing. This is pretty cool--first, you're delegating DOM display out of the parent class component into the functional component 'below' it. You're also using methods built in that same parent component and sharing them with the child. The child triggers that function, which still changes properties of the class parent component (state, in this case). React is filled with these instances of parent-child communication. It's both a strength and a limitation of working with this environment!
Last updated