eolas/neuron/23e0f0eb-f9c9-467a-86da-ba26a6fd9b56/Functions.md
2025-01-21 17:10:11 +00:00

39 lines
629 B
Markdown

---
tags:
- typescript
- react
---
# Functions
Continuing from the other examples of React Typescript, we could do standard
listing function, like:
```tsx
<ul>
{people.map((person) => {
return <li>{person.name}</li>;
})}
</ul>
```
But it's neater to do it with a function defined within the `List` component:
```tsx
const renderList = (): JSX.Element[] => {
return people.map((person) => {
return (
<li>
<div>{person.name}</div>
<div>{person.age}</div>
</li>
);
});
};
```
And then change the eariler list to a function invocation:
```tsx
<ul>{renderList()}<ul>
```