How Control Props Work
In this lesson, we'll make the Expandable component work so that the elements expand one at a time
We'll cover the following...
Controlled vs. Uncontrolled Elements
Consider a simple input field.
Press + to interact
<input />
In React, a controlled input element will be defined like this:
Press + to interact
<input value={someValue} onChange={someHandler} />
Hmm, that’s different.
A controlled input component has its value
and onChange
handler managed externally.
This is exactly what we aim for when implementing the control props pattern. We want the internally-managed state to be manageable from the outside via props!
Implementing in Expandable
How it Works
The implementation is quite simple, but we need to understand how it works before we delve into writing some code.
The default usage of the Expandable
component is as shown below:
Press + to interact
<Expandable><Expandable.Header>{someHeader}</Expandable.Header><Expandable.Icon /><Expandable.Body>{someContent}</Expandable.Body></Expandable>
Within the ...
Access this course and 1400+ top-rated courses and projects.