wip: add list question

feat/questions
Arik Chakma 1 year ago
parent 88da459e8e
commit 08a6d6ef91
  1. 17
      src/data/question-groups/react/content/render-list.md
  2. 5
      src/data/question-groups/react/react.md

@ -0,0 +1,17 @@
In React, you can render a list by using the JavaScript `map` function to iterate over an array of items and return a JSX element for each item. It's important to provide a unique `key` prop to each element in the list for React's diffing algorithm to function efficiently during re-renders. Here's a basic example:
```javascript
const items = ['Apple', 'Banana', 'Cherry'];
function FruitList() {
return (
<ul>
{items.map((fruit, index) => (
<li key={index}>{fruit}</li>
))}
</ul>
);
}
```
> Note: While using the index as a key can work in some cases, it's generally not recommended for dynamic lists where items can be added, removed, or reordered.

@ -307,4 +307,9 @@ questions:
topics:
- 'Core'
- 'Beginner'
- question: How to render a list in React?
answer: render-list.md
topics:
- 'Core'
- 'Beginner'
---

Loading…
Cancel
Save