We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 933f555 commit 47b41d4Copy full SHA for 47b41d4
typescript/react-component-prop.md
@@ -0,0 +1,19 @@
1
+# React get a components prop types
2
+
3
+When using TS with React you may want to get the types of another component.
4
5
+```tsx
6
+const MyButton: React.FC<{
7
+ value: string;
8
+ onChange: (newValue: string) => void;
9
+}> = () => {
10
+ return <button value={value} onchange={onChange} />;
11
+};
12
+type ButtonProps = React.ComponentProps<typeof MyButton>;
13
14
+// equivalent:
15
16
+type ButtonProps = { value: string; onChange: (newValue: string) => void };
17
+```
18
19
+ This can be particularly useful when using an external library that does not expose the types for a component.
0 commit comments