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 => <
related reading
- Typing Component Props | React TypeScript Cheatsheetreact-typescript-cheatsheet.netlify.app
- Build your own Reactpomb.us
- Useful Patterns by Use Case | React TypeScript Cheatsheetreact-typescript-cheatsheet.netlify.app
- You Might Not Need an Effect – Reactreact.dev
- TypeScript: Documentation - More on Functionstypescriptlang.org
- TypeScript: Documentation - The Basicstypescriptlang.org
- Tutorial: Tic-Tac-Toe – Reactreactjs.org
- Composition vs Inheritance – Reactreactjs.org
- Tao of React - Software Design, Architecture & Best Practices | Alex Kondovalexkondov.com
- TypeScript: Documentation - Object Typestypescriptlang.org
- How Props Work in React – A Beginner's Guidefreecodecamp.org
- Making Sense of React Server Components • Josh W. Comeaujoshwcomeau.com