From 0b89cc61818601dfc426649fdb1a9ad67c681131 Mon Sep 17 00:00:00 2001 From: Mikey Binns <38146638+mikeybinns@users.noreply.github.com> Date: Tue, 2 Apr 2024 23:54:51 +0100 Subject: [PATCH] Add component props docs (#60350) * add docs about component props * Apply suggestions from code review Co-authored-by: Lena Morita --------- Co-authored-by: mikeybinns Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: rafaucau --- packages/components/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/components/README.md b/packages/components/README.md index f3e4399fe3d51..df92e8db57be4 100644 --- a/packages/components/README.md +++ b/packages/components/README.md @@ -57,6 +57,19 @@ const Example = () => { }; ``` +### TypeScript + +This package exposes its own types for the components it exports, however it doesn't export its own types for component props. If you need to extract the props type, please use `React.ComponentProps` to get the types from the element. + +```tsx +import type { ComponentProps } from 'react'; +import { Button } from '@wordpress/components'; + +export default function MyButton( props: ComponentProps< typeof Button > ) { + return ; +} +``` + ## Docs & examples You can browse the components docs and examples at [https://wordpress.github.io/gutenberg/](https://wordpress.github.io/gutenberg/)