Skip to content

Commit

Permalink
[docs] Add TypeScript guide on the polymorphic components (mui#32168)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova authored May 11, 2022
1 parent 6ad56c2 commit 804aafd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions docs/data/material/guides/typescript/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ by default and loose via opt-in.

Moved to [/customization/theming/#custom-variables](/material-ui/customization/theming/#custom-variables).

## Usage of `component` prop
## Complications with the `component` prop

Moved to [/guides/composition/#with-typescript](/material-ui/guides/composition/#with-typescript).
Because of some TypeScript limitations, using the `component` prop can be problematic if you are creating your custom component based on the Material UI's components.
For the composition of the components, you will likely need to use one of these two options:

1. Wrap the Material UI component in order to enhance it
2. Use the `styled()` utility in order to customize the styles of the component

If you are using the first option, take a look at the [composition guide](/material-ui/guides/composition/#with-typescript) for more details.

If you are using the `styled()` utility (regardless of whether it comes from `@mui/material` or `@emotion/styled`), you will need to cast the resulting component as shown below:

```tsx
import Button from '@mui/material/Button';
import { styled } from '@mui/material/styles';

const CustomButton = styled(Button)({
// your custom styles go here
}) as typeof Button;
```

0 comments on commit 804aafd

Please sign in to comment.