eolas/neuron/2abd5c63-27cc-420e-b0df-76bdd7f8acb1/React_Components.md
2025-03-26 17:50:46 +00:00

32 lines
768 B
Markdown

---
tags:
- typescript
- react
---
# Components
We write functional components in the manner of a normal
[function](Functions.md) that take
a props argument and return a JSX element.
```jsx
interface IProps = {
message: string;
};
const App = ({message}: IProps): JSX.Element => <div>{message}</div>;
```
## `React.FunctionComponent` / `React.FC`
It used to be the case that you would type a function component like so:
```jsx
const App: React.FunctionComponent<{ message: string }> = ({ message }) => (
<div>{message}</div>
);
```
This is now discouraged as it means the component can always accept children,
even when you do not want this to be the case. There are several other minor
drawerbacks but it's generally best to leave out the declaration.