Skip to content

Commit e7fd754

Browse files
committed
fix: 3a08e1e2-fbe9-49c8-b260-6e61cae14553
1 parent 103fb99 commit e7fd754

File tree

1 file changed

+15
-21
lines changed
  • questions/how-does-virtual-dom-in-react-work-what-are-its-benefits-and-downsides

1 file changed

+15
-21
lines changed

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://reactjs.org/docs/reconciliation.html)
79-
- [Understanding the virtual DOM](https://medium.com/@deathmood/how-to-write-your-own-virtual-dom-ee74acc13060)
80-
- [React performance optimization](https://reactjs.org/docs/optimizing-performance.html)
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/)

0 commit comments

Comments
 (0)