Skip to content

Commit a3f3936

Browse files
authored
Merge branch 'main' into yuhang/update-react-links
2 parents 8c071b8 + 0ef723a commit a3f3936

File tree

3 files changed

+21
-25
lines changed
  • questions
    • explain-the-composition-pattern-in-react
    • how-does-virtual-dom-in-react-work-what-are-its-benefits-and-downsides
    • what-are-react-fragments-used-for

3 files changed

+21
-25
lines changed

questions/explain-the-composition-pattern-in-react/en-US.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ function App() {
8282

8383
## Further reading
8484

85-
- [React patterns: Composition](https://reactpatterns.com/#composition)
85+
- [Composition in React](https://krasimir.gitbooks.io/react-in-patterns/content/chapter-04/)
8686
- [Medium article on React composition](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0)

questions/how-does-virtual-dom-in-react-work-what-are-its-benefits-and-downsides/en-US.mdx

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,19 @@ The virtual DOM is a concept where a virtual representation of the UI is kept in
2424
### Code example
2525

2626
```jsx
27-
class MyComponent extends React.Component {
28-
constructor(props) {
29-
super(props);
30-
this.state = { count: 0 };
31-
}
32-
33-
increment = () => {
34-
this.setState({ count: this.state.count + 1 });
35-
};
36-
37-
render() {
38-
return (
39-
<div>
40-
<p>{this.state.count}</p>
41-
<button onClick={this.increment}>Increment</button>
42-
</div>
43-
);
44-
}
27+
import { useState } from 'react';
28+
29+
function MyComponent() {
30+
const [count, setCount] = useState(0);
31+
32+
const increment = () => setCount(count + 1);
33+
34+
return (
35+
<div>
36+
<p>{count}</p>
37+
<button onClick={increment}>Increment</button>
38+
</div>
39+
);
4540
}
4641
```
4742

@@ -75,6 +70,5 @@ In this example, when the button is clicked, the state changes, triggering a new
7570

7671
## Further reading
7772

78-
- [React documentation on reconciliation](https://react.dev/learn/preserving-and-resetting-state)
79-
- [Understanding the virtual DOM](https://medium.com/@deathmood/how-to-write-your-own-virtual-dom-ee74acc13060)
80-
- [React memo performance optimization](https://react.dev/reference/react/memo#skipping-re-rendering-when-props-are-unchanged)
73+
- [React Docs on Reconciliation](https://react.dev/learn/render-and-commit)
74+
- [What is the Virtual DOM in React?](https://www.freecodecamp.org/news/what-is-the-virtual-dom-in-react/)

questions/what-are-react-fragments-used-for/en-US.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ If you need to add keys to the elements within a fragment, you must use the full
5959

6060
```jsx
6161
return (
62-
<React.Fragment>
62+
<>
6363
{items.map((item) => (
64-
<ChildComponent key={item.id} />
64+
<React.Fragment key={item.id}>
65+
<ChildComponent />
66+
</React.Fragment>
6567
))}
66-
</React.Fragment>
68+
</>
6769
);
6870
```
6971

0 commit comments

Comments
 (0)