I'm learning how to use React-TypeScript, and I'm confused with how React.FC and generics work together.
So I have a couple of questions relating to the code below (a functional component returning a list item):
1.) Do you have to pass props as a generic? Or could you simply write
const TodoListItem: React.FC = (props) => {
//code
}
2.) How is it that todo is able to be destructured out of <TodoListItemProps> ?
3.) Why is a return type not defined? Shouldn't it be written as :
const TodoListItem: React.FC<TodoListItemProps> = ({todo}):TodoListItemProps
Full code here:
interface TodoListItemProps {
todo: {
text:string
complete:boolean
}
}
const TodoListItem: React.FC<TodoListItemProps> = ({todo}) => {
return(
<li>
<label>
{todo.text}
</label>
</li>
)
}