DEV Community

Discussion on: My React-TypeScript Cheat Sheet

Collapse
 
irvingarmenta profile image
Irving Armenta

I use the included FC type from React for Functional Components:

import React, { FC } from 'react'; 

// typing with the HTMLAttributes extension
type FunctionalCompType = { 
     id: string; 
// ..other stuff
} & HTMLAttributes<HTMLButtonElement> 

const FunctionalComp: FC<FunctionalCompType> = props => {
       const { children, id, ...buttonProps } = props;
       return <button {...buttonProps} >{children}</button>
};
Collapse
 
idoshamun profile image
Ido Shamun

That's nice! I didn't know about it.
But actually, I use strict lint rules so I must define the function argument type and return type.