What is correct way how to create functional component in react using typescript ?
- Should I use
interfaceor type forprops? - Should I use
React.FCorReact.FunctionComponent? - How can I validate
propsusingeslint?
Right now, my typically components looks like:
interface IProps {
color: string;
}
const Example = (props: IProps) => {
const { color } = props;
return (
<>
{color}
</>
);
};
I am not sure if it best way...
Also I dont know how to validate props usingeslint`, for example when I want to pass down color as a number..
const Example = (props: IProps) => {toconst Example: React.FC<IProps> = (props) => {. In addition, your interface is fine!