Skip to content

Commit 0ef723a

Browse files
authored
qns: address user feedback (#4)
Addressed quiz questions' user feedback. Each commit is labelled with an `id` pointing to the User Feedback google sheet.
1 parent 98f1045 commit 0ef723a

File tree

4 files changed

+22
-26
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
    • what-is-the-useref-hook-in-react-and-when-should-it-be-used

4 files changed

+22
-26
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,6 +82,6 @@ function App() {
8282

8383
## Further reading
8484

85-
- [React documentation on composition vs inheritance](https://reactjs.org/docs/composition-vs-inheritance.html)
85+
- [Composition in React](https://krasimir.gitbooks.io/react-in-patterns/content/chapter-04/)
8686
- [React patterns: Composition](https://reactpatterns.com/#composition)
8787
- [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://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/)

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

questions/what-is-the-useref-hook-in-react-and-when-should-it-be-used/en-US.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ In this example, `prevCountRef` is used to keep a reference to the previous valu
108108

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

0 commit comments

Comments
 (0)