I
I
Ilya Olovyannikov2022-02-17 19:24:33
typescript
Ilya Olovyannikov, 2022-02-17 19:24:33

How to correctly pass props to a React component using TypeScript?

Greetings!

What is the difference between these notations? And which option is better and why?

export const AuthDialog = ({onClose, isVisible}: AuthDialogInterface): JSX.Element => //.....


export const AuthDialog: FC<AuthDialogInterface> = ({onClose, isVisible}): JSX.Element => //.....

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexandroppolus, 2022-02-17
@Alexandroppolus

In the second case, you can pass children, and you do not need to add ": JSX.Element"

N
Natebash, 2022-02-17
@Natebash

It's better to do it like this:

export const AuthDialog: FC<AuthDialogInterface> = ({onClose, isVisible}) => //.....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question