Skip to content

Commit 2869b01

Browse files
committed
Update thinking-in-react.md to filter products in FilterableProductTable
1 parent 4c45058 commit 2869b01

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/docs/thinking-in-react.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ You'll see here that we have five components in our simple app. We've italicized
4545

4646
1. **`FilterableProductTable` (orange):** contains the entirety of the example
4747
2. **`SearchBar` (blue):** receives all *user input*
48-
3. **`ProductTable` (green):** displays and filters the *data collection* based on *user input*
48+
3. **`ProductTable` (green):** displays the *data collection* based on *user input*
4949
4. **`ProductCategoryRow` (turquoise):** displays a heading for each *category*
5050
5. **`ProductRow` (red):** displays a row for each *product*
5151

@@ -106,8 +106,8 @@ So finally, our state is:
106106

107107
## Step 4: Identify Where Your State Should Live
108108

109-
<p data-height="600" data-theme-id="0" data-slug-hash="ORzEkG" data-default-tab="js" data-user="lacker" data-embed-version="2" class="codepen">See the Pen <a href="http://codepen.io/lacker/pen/ORzEkG/">Thinking In React: Step 4</a> by Kevin Lacker (<a href="http://codepen.io/lacker">@lacker</a>) on <a href="http://codepen.io">CodePen</a>.</p>
110-
<script async src="//assets.codepen.io/assets/embed/ei.js"></script>
109+
<p data-height="600" data-theme-id="0" data-slug-hash="jGVpqQ" data-default-tab="js" data-user="danielsbird" data-embed-version="2" data-pen-title="Thinking In React: Step 4" class="codepen">See the Pen <a href="https://codepen.io/danielsbird/pen/jGVpqQ/">Thinking In React: Step 4</a> by Daniel Bird (<a href="https://codepen.io/danielsbird">@danielsbird</a>) on <a href="https://codepen.io">CodePen</a>.</p>
110+
<script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
111111

112112
OK, so we've identified what the minimal set of app state is. Next, we need to identify which component mutates, or *owns*, this state.
113113

@@ -122,17 +122,17 @@ For each piece of state in your application:
122122

123123
Let's run through this strategy for our application:
124124

125-
* `ProductTable` needs to filter the product list based on state and `SearchBar` needs to display the search text and checked state.
125+
* `ProductTable` needs to display the filtered product list and `SearchBar` needs to display the search text and checked state.
126126
* The common owner component is `FilterableProductTable`.
127127
* It conceptually makes sense for the filter text and checked value to live in `FilterableProductTable`
128128

129-
Cool, so we've decided that our state lives in `FilterableProductTable`. First, add an instance property `this.state = {filterText: '', inStockOnly: false}` to `FilterableProductTable`'s `constructor` to reflect the initial state of your application. Then, pass `filterText` and `inStockOnly` to `ProductTable` and `SearchBar` as a prop. Finally, use these props to filter the rows in `ProductTable` and set the values of the form fields in `SearchBar`.
129+
Cool, so we've decided that our state lives in `FilterableProductTable`. First, add an instance property `this.state = {filterText: '', inStockOnly: false}` to `FilterableProductTable`'s `constructor` to reflect the initial state of your application. Next, instead of passing `this.props.products` to ProductTable, pass only the products that match the search text and checkbox value. Then, pass `filterText` and `inStockOnly` to `SearchBar` as a prop. Finally, use these props to set the values of the form fields in `SearchBar`.
130130

131131
You can start seeing how your application will behave: set `filterText` to `"ball"` and refresh your app. You'll see that the data table is updated correctly.
132132

133133
## Step 5: Add Inverse Data Flow
134134

135-
<p data-height="600" data-theme-id="0" data-slug-hash="qRqmjd" data-default-tab="js,result" data-user="rohan10" data-embed-version="2" data-pen-title="Thinking In React: Step 5" class="codepen">See the Pen <a href="http://codepen.io/rohan10/pen/qRqmjd">Thinking In React: Step 5</a> on <a href="http://codepen.io">CodePen</a>.</p>
135+
<p data-height="600" data-theme-id="0" data-slug-hash="qPqyRN" data-default-tab="js,result" data-user="danielsbird" data-embed-version="2" data-pen-title="Thinking In React: Step 5" class="codepen">See the Pen <a href="https://codepen.io/danielsbird/pen/qPqyRN/">Thinking In React: Step 5</a> by Daniel Bird (<a href="https://codepen.io/danielsbird">@danielsbird</a>) on <a href="https://codepen.io">CodePen</a>.</p>
136136
<script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
137137

138138
So far, we've built an app that renders correctly as a function of props and state flowing down the hierarchy. Now it's time to support data flowing the other way: the form components deep in the hierarchy need to update the state in `FilterableProductTable`.

0 commit comments

Comments
 (0)