Skip to content

Commit 03b63eb

Browse files
committed
Address some feedback
1 parent 77496ef commit 03b63eb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/content/reference/rules/components-and-hooks-must-be-pure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function NewsFeed({ items }) {
2222
const filteredItems = items.filter(item => item.isDisplayed === true);
2323
return (
2424
<ul>
25-
{filteredItems.map(item => <li>{item.text}</li>}
25+
{filteredItems.map(item => <li key={item.id}>{item.text}</li>}
2626
</ul>
2727
);
2828
}

src/content/reference/rules/react-orchestrates-components-and-hooks.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ function BlogPost() {
2525

2626
```js {3}
2727
function BlogPost() {
28-
ReactDOM.render(
29-
Layout({ children: Article() }), // ❌ Never call them directly
30-
/* ... */
31-
);
28+
return <Layout>{Article()}</Layout> // ❌ Never call them directly
3229
}
3330
```
3431

35-
Letting React orchestrate rendering allows a number of benefits:
32+
If a component contains hooks, it's easy to violate the Rules of Hooks when components are called directly in a loop or conditionally.
33+
34+
Letting React orchestrate rendering also allows a number of benefits:
3635

3736
* **Components become more than functions.** React can augment them with features like _local state_ through Hooks that are tied to the component's identity in the tree.
3837
* **Component types participate in reconcilation.** By letting React call your components, you also tell it more about the conceptual structure of your tree. For example, when you move from rendering `<Feed>` to the `<Profile>` page, React won’t attempt to re-use them.
@@ -46,6 +45,8 @@ Hooks should only be called inside of components. Never pass it around as a regu
4645

4746
Hooks allow you to augment a component with React features. They should always be called as a function, and never passed around as a regular value. This enables _local reasoning_, or the ability for developers to understand everything a component can do by looking at that component in isolation.
4847

48+
Passing around hooks as regular values also inhibits the compiler at performing optimizations. Breaking this rule will de-optimize your component.
49+
4950
```js {2}
5051
function ChatInput() {
5152
const useDataWithLogging = withLogging(useData); //

0 commit comments

Comments
 (0)