You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/data/material/guides/composition/composition.md
+18-1Lines changed: 18 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,6 +47,23 @@ The following example will render the `List` component with a `<menu>` element a
47
47
48
48
This pattern is very powerful and allows for great flexibility, as well as a way to interoperate with other libraries, such as your favorite routing or forms library.
49
49
50
+
### Passing other React components
51
+
52
+
You can pass any other React component to `component` prop. For example, you can pass `Link` component from `react-router-dom`:
53
+
54
+
```tsx
55
+
import { Link } from'react-router-dom';
56
+
importButtonfrom'@mui/material/Button';
57
+
58
+
function Demo() {
59
+
return (
60
+
<Buttoncomponent={Link}to="/react-router">
61
+
React router link
62
+
</Button>
63
+
);
64
+
}
65
+
```
66
+
50
67
### With TypeScript
51
68
52
69
To be able to use the `component` prop, the type of the props should be used with type arguments. Otherwise, the `component` prop will not be present.
@@ -71,7 +88,7 @@ You can find a code example with the Button and react-router-dom in [these demos
71
88
72
89
### Generic
73
90
74
-
It's also possible to have a generic `CustomComponent` which will accept any React component, and HTML elements.
91
+
It's also possible to have a generic custom component which will accept any React component, and HTML elements.
75
92
76
93
```ts
77
94
function GenericCustomComponent<CextendsReact.ElementType>(
0 commit comments