2.3 - Concept Component
Okay, now that we've got our two functional children classes, ConceptList
and Concept
, we can go ahead and work on the logic in our ReactConceptsApp
component.
imports
First thing we can do is add our new ConceptList
component to our imports. All the imports together should now look like this:
render()
Additionally, now that we've set up our child components, we can now update our render to use these components. We need to use our ConceptList
component, and set its props of concepts and toggle. So we can pass along our state to concepts, and we need to create a method to pass to toggle
. Let's go ahead and just call it toggleConcept
and set up our render()
to look like this.
toggleConcept
Now, we're calling a custom function called toggleConcept
, but we need to actually define what toggleConcept
does. Our objective is to take the concepts and compare them against the concept list, using the lodash find
method.
This find
method compares a collection to a second thing (in this case concepts
) and returns the first thing it finds truthy for. Then, we need it to set concept.done to the opposite of what it currently is, essentially toggling it. Yea, lodash
is sweet.
Finally, we need to set state back to include the updated toggle on done
. To see for yourself, what concepts looks like when it comes back, feel free to add a console.log
at the first line of the method.
The View:
Here's what you should currently see in the app:
Completed Code
To see the complete code for ReactConceptsApp so far, check below to make sure yours matches up.
Next, we're going to figure out how to add a new concept.
Last updated