[material-ui][docs] Document the correct way to extend a component
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
We are using Material-UI as the base of a project, but are running in to issues extending components
import { Link, LinkProps } from "@material-ui/core";
export const HnLink = Link;
Works fine
import { Link, LinkProps } from "@material-ui/core";
export const HnLink: React.FC<LinkProps> = props => {
// Some extra functionality
return <Link {...props} />
}
Does not accept component and to props, resulting in TypeScript errors.
Type '{ to: string; component: typeof Link; }' is not assignable to type 'IntrinsicAttributes & AnchorHTMLAttributes<HTMLAnchorElement> & Pick<OverrideProps<TypographyTypeMap<{}, "span">, "span">, "ref" | ... 262 more ... | "variantMapping"> & { ...; } & CommonProps<...> & Pick<...> & { ...; }'.
Property 'to' does not exist on type 'IntrinsicAttributes & AnchorHTMLAttributes<HTMLAnchorElement> & Pick<OverrideProps<TypographyTypeMap<{}, "span">, "span">, "ref" | ... 262 more ... | "variantMapping"> & { ...; } & CommonProps<...> & Pick<...> & { ...; }'.ts(2322)
The same is true of Tabs, wherein wrapping Tabs in our own component causes onChange to not be accepted
Type '(event: ChangeEvent<{}>, value: number) => void' is not assignable to type '((event: ChangeEvent<{}>, value: any) => void) & ((event: FormEvent<HTMLButtonElement>) => void)'.
Type '(event: ChangeEvent<{}>, value: number) => void' is not assignable to type '(event: FormEvent<HTMLButtonElement>) => void'.ts(2322)
As also seen here: https://github.com/mui-org/material-ui/issues/17454
Is there a 'correct' way to wrap a Material-UI component that can alleviate typing issues?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the Link and Tabs wrapper examples and the referenced issue #17454. Determine the supported way to preserve component props and callbacks when wrapping these components, then document that guidance with matching examples; done means the documentation addresses the reported TypeScript errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- documentation, frontend
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100