Useful Patterns by Use Case | React TypeScript Cheatsheets
react-typescript-cheatsheet.netlify.app · 3,269 words · saved by 1 readers
Wrapping/Mirroring
Wrapping/Mirroring Wrapping/Mirroring a HTML Element Usecase: you want to make a <Button> that takes all the normal props of <button> and does extra stuff. Strategy: extend React.ComponentPropsWithoutRef<'button'> // usage function App() { // Type '"foo"' is not assignable to type '"button" | "submit" | "reset" | undefined'.(2322) // return <Button type="foo"> sldkj </Button> // no error return <Button type="button"> text </Button>; } // implementation export interface ButtonProps extends React.ComponentPropsWithoutRef<"button"> { specialProp?: string; } export function…
related reading
- Typing Component Props | React TypeScript Cheatsheetreact-typescript-cheatsheet.netlify.app
- Tutorial: Tic-Tac-Toe – Reactreactjs.org
- Function Components | React TypeScript Cheatsheetreact-typescript-cheatsheet.netlify.app
- Tao of React - Software Design, Architecture & Best Practices | Alex Kondovalexkondov.com
- Shikishiki.style
- How to Steal Any React Componentfant.io
- Composition vs Inheritance – Reactreactjs.org
- React Components, Templates & Themes — 12,000+ Crafted UI | 21st21st.dev
- Building Bulletproof React Components - Shu Dingshud.in
- React graph viscrubier.github.io
- Typescript utility types that you must know - DEV Communitydev.to
- How Props Work in React – A Beginner's Guidefreecodecamp.org