flâneur — a map of the web's best reading

Function Components | React TypeScript Cheatsheets

react-typescript-cheatsheet.netlify.app · 509 words · saved by 1 readers

These can be written as normal functions that take a props argument and return a JSX element.

These can be written as normal functions that take a props argument and return a JSX element. // Declaring type of props - see "Typing Component Props" for more examples type AppProps = { message : string ; } ; /* use `interface` if exporting so that consumers can extend */ // Easiest way to declare a Function Component; return type is inferred. const App = ( { message } : AppProps ) => < div > { message } </ div > ; // You can choose to annotate the return type so an error is raised if you accidentally return some other type const App = ( { message } : AppProps ) : React . JSX . Element => <

Explore this link on the map →

related reading