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
- You Might Not Need an Effect – Reactreact.dev
- Build your own Reactpomb.us
- Function Components | React TypeScript Cheatsheetreact-typescript-cheatsheet.netlify.app
- Implementing React from scratchrob.directory
- Tutorial: Tic-Tac-Toe – Reactreactjs.org
- Blogged Answers: A (Mostly) Complete Guide to React Rendering Behavior · Mark's Dev Blogblog.isquaredsoftware.com
- Tao of React - Software Design, Architecture & Best Practices | Alex Kondovalexkondov.com
- Composition vs Inheritance – Reactreactjs.org
- Typescript utility types that you must know - DEV Communitydev.to
- Why React Re-Renders • Josh W. Comeaujoshwcomeau.com
- React graph viscrubier.github.io