Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ function App() {

## Further reading

- [React documentation on composition vs inheritance](https://reactjs.org/docs/composition-vs-inheritance.html)
- [Composition in React](https://krasimir.gitbooks.io/react-in-patterns/content/chapter-04/)
- [React patterns: Composition](https://reactpatterns.com/#composition)
- [Medium article on React composition](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0)
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,19 @@ The virtual DOM is a concept where a virtual representation of the UI is kept in
### Code example

```jsx
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = { count: 0 };
}

increment = () => {
this.setState({ count: this.state.count + 1 });
};

render() {
return (
<div>
<p>{this.state.count}</p>
<button onClick={this.increment}>Increment</button>
</div>
);
}
import { useState } from 'react';

function MyComponent() {
const [count, setCount] = useState(0);

const increment = () => setCount(count + 1);

return (
<div>
<p>{count}</p>
<button onClick={increment}>Increment</button>
</div>
);
}
```

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

## Further reading

- [React documentation on reconciliation](https://reactjs.org/docs/reconciliation.html)
- [Understanding the virtual DOM](https://medium.com/@deathmood/how-to-write-your-own-virtual-dom-ee74acc13060)
- [React performance optimization](https://reactjs.org/docs/optimizing-performance.html)
- [React Docs on Reconciliation](https://react.dev/learn/render-and-commit)
- [What is the Virtual DOM in React?](https://www.freecodecamp.org/news/what-is-the-virtual-dom-in-react/)
8 changes: 5 additions & 3 deletions questions/what-are-react-fragments-used-for/en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ If you need to add keys to the elements within a fragment, you must use the full

```jsx
return (
<React.Fragment>
<>
{items.map((item) => (
<ChildComponent key={item.id} />
<React.Fragment key={item.id}>
<ChildComponent />
</React.Fragment>
))}
</React.Fragment>
</>
);
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ In this example, `prevCountRef` is used to keep a reference to the previous valu

- [React documentation on `useRef`](https://reactjs.org/docs/hooks-reference.html#useref)
- [Using the `useRef` hook](https://reactjs.org/docs/hooks-faq.html#is-there-something-like-instance-variables)
- [Common use cases for `useRef`](https://blog.logrocket.com/how-to-use-react-useref-hook/)
- [Common use cases for `useRef`](https://dev.to/kirubelkinfe/mastering-useref-in-react-with-typescript-4-different-use-cases-for-useref-2a87)