eolas/neuron/7c141533-1806-4f5c-a70e-7527be05b1c5/Functions.md

40 lines
629 B
Markdown
Raw Normal View History

2024-12-09 18:34:15 +00:00
---
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>
```