...
/Creating a Single Orchestrating Component
Creating a Single Orchestrating Component
Learn how to collect and refactor the repeated search sort and filter components into a single, reusable React component.
Reviewing the effects of refactoring
Our SearchInput
, Sorters
, and Filters
components have all been refactored to use the React render prop pattern. The code for the widgets
and people
data is far less complex than what we had previously in the App
component. Here’s what the widgets
data looks like now:
Press + to interact
<h2>Widgets:</h2>// This component will render a search input and corresponding searched list<SearchInputdata={widgets}renderItem={(widget) => <WidgetRenderer {...widget} />}initialSearchQuery=""searchKeys={["title", "description"]}/>// This component will render the sorters drop down and corresponding sorted list<Sortersdata={widgets}renderItem={(widget) => <WidgetRenderer {...widget}/>}label="Sort options for widgets!"initialSortProperty="title"initialIsDescending={false}/>// This component will render the truthy false radio buttons and corresponding filtered list<Filtersdata={widgets}renderItem={(widget) => <WidgetRenderer {...widget}/>}label="Widget filters!"initialFilterProperties={[{property: "title",isTruthySelected: true}]}/>
This is what the people
data looks like:
Press + to interact
<h2>People:</h2>// This component will render a search input and corresponding searched list<SearchInputdata={people}renderItem={(person) => <PersonRenderer {...person} />}initialSearchQuery="Bob"searchKeys={["firstName", "lastName", "eyeColor"]}/>// This component will render the sorters drop down and corresponding sorted list<Sortersdata={people}renderItem={(person) => <PersonRenderer {...person} />}label="Sort options for people!"initialSortProperty="firstName"initialIsDescending={false}/>// This component will render the truthy false radio buttons and corresponding filtered list<Filtersdata={people}renderItem={(person) => <PersonRenderer {...person} />}label="People filters!"initialFilterProperties={[{property: "firstName",isTruthySelected: true}]}/>
One problem with this composition is that each functionality renders a separate list of ...