From 0b4e9c8d03e2c8fbaaa6bec7ea4392e214368f7a Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Fri, 7 May 2021 07:05:20 -0700 Subject: [PATCH 1/7] compose: Add types to useRefEffect and clipboard hooks --- package-lock.json | 6 ++++++ package.json | 1 + packages/compose/README.md | 12 +++++------ .../src/hooks/use-copy-on-click/index.js | 20 ++++++++++++++----- .../src/hooks/use-copy-to-clipboard/index.js | 19 ++++++++++++------ .../compose/src/hooks/use-ref-effect/index.js | 9 +++++---- packages/compose/tsconfig.json | 3 +++ 7 files changed, 49 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index a5a2e9ef4158cb..787cf33c5035f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11566,6 +11566,12 @@ "integrity": "sha512-1UzDldn9GfYYEsWWnn/P4wkTlkZDH7lDb0wBMGbtIQc9zXEQq7FlKBdZUn6OBqD8sKZZ2RQO2mAjGpXiDGoRmQ==", "dev": true }, + "@types/clipboard": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@types/clipboard/-/clipboard-2.0.1.tgz", + "integrity": "sha512-gJJX9Jjdt3bIAePQRRjYWG20dIhAgEqonguyHxXuqALxsoDsDLimihqrSg8fXgVTJ4KZCzkfglKtwsh/8dLfbA==", + "dev": true + }, "@types/color-convert": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@types/color-convert/-/color-convert-2.0.0.tgz", diff --git a/package.json b/package.json index 8050fb330f5004..7056b6182131fe 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,7 @@ "@testing-library/react": "11.2.2", "@testing-library/react-native": "7.1.0", "@types/classnames": "2.2.10", + "@types/clipboard": "2.0.1", "@types/eslint": "6.8.0", "@types/estree": "0.0.44", "@types/highlight-words-core": "1.2.0", diff --git a/packages/compose/README.md b/packages/compose/README.md index 7a6be1782b1959..d477d414eba62f 100644 --- a/packages/compose/README.md +++ b/packages/compose/README.md @@ -166,7 +166,7 @@ Copies the text to the clipboard when the element is clicked. _Parameters_ -- _ref_ `Object`: Reference with the element. +- _ref_ `import('react').RefObject>`: Reference with the element. - _text_ `string|Function`: The text to copy. - _timeout_ `number`: Optional timeout to reset the returned state. 4 seconds by default. @@ -180,12 +180,12 @@ Copies the given text to the clipboard when the element is clicked. _Parameters_ -- _text_ `text|Function`: The text to copy. Use a function if not already available and expensive to compute. +- _text_ `string | (() => string)`: The text to copy. Use a function if not already available and expensive to compute. - _onSuccess_ `Function`: Called when to text is copied. _Returns_ -- `RefObject`: A ref to assign to the target element. +- `import('react').Ref`: A ref to assign to the target element. # **useDebounce** @@ -398,12 +398,12 @@ callback will be called multiple times for the same node. _Parameters_ -- _callback_ `Function`: Callback with ref as argument. -- _dependencies_ `Array`: Dependencies of the callback. +- _callback_ `(node: Node) => (() => void) | undefined`: Callback with ref as argument. +- _dependencies_ `import('react').DependencyList`: Dependencies of the callback. _Returns_ -- `Function`: Ref callback. +- `(node: Node) => void`: Ref callback. # **useResizeObserver** diff --git a/packages/compose/src/hooks/use-copy-on-click/index.js b/packages/compose/src/hooks/use-copy-on-click/index.js index 33a14c0224add3..99c595be99a202 100644 --- a/packages/compose/src/hooks/use-copy-on-click/index.js +++ b/packages/compose/src/hooks/use-copy-on-click/index.js @@ -9,32 +9,40 @@ import Clipboard from 'clipboard'; import { useRef, useEffect, useState } from '@wordpress/element'; import deprecated from '@wordpress/deprecated'; +/* eslint-disable jsdoc/no-undefined-types */ /** * Copies the text to the clipboard when the element is clicked. * * @deprecated * - * @param {Object} ref Reference with the element. - * @param {string|Function} text The text to copy. - * @param {number} timeout Optional timeout to reset the returned + * @param {import('react').RefObject>} ref Reference with the element. + * @param {string|Function} text The text to copy. + * @param {number} timeout Optional timeout to reset the returned * state. 4 seconds by default. * * @return {boolean} Whether or not the text has been copied. Resets after the * timeout. */ export default function useCopyOnClick( ref, text, timeout = 4000 ) { + /* eslint-enable jsdoc/no-undefined-types */ deprecated( 'wp.compose.useCopyOnClick', { since: '10.3', plugin: 'Gutenberg', alternative: 'wp.compose.useCopyToClipboard', } ); + /** @type {import('react').MutableRefObject} */ const clipboard = useRef(); const [ hasCopied, setHasCopied ] = useState( false ); useEffect( () => { + /** @type {number | undefined} */ let timeoutId; + if ( ! ref.current ) { + return; + } + // Clipboard listens to click events. clipboard.current = new Clipboard( ref.current, { text: () => ( typeof text === 'function' ? text() : text ), @@ -48,7 +56,7 @@ export default function useCopyOnClick( ref, text, timeout = 4000 ) { // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680 if ( trigger ) { - trigger.focus(); + /** @type {HTMLElement} */ ( trigger ).focus(); } if ( timeout ) { @@ -59,7 +67,9 @@ export default function useCopyOnClick( ref, text, timeout = 4000 ) { } ); return () => { - clipboard.current.destroy(); + if ( clipboard.current ) { + clipboard.current.destroy(); + } clearTimeout( timeoutId ); }; }, [ text, timeout, setHasCopied ] ); diff --git a/packages/compose/src/hooks/use-copy-to-clipboard/index.js b/packages/compose/src/hooks/use-copy-to-clipboard/index.js index b9cbf38fa3e996..9e9cb4f896e520 100644 --- a/packages/compose/src/hooks/use-copy-to-clipboard/index.js +++ b/packages/compose/src/hooks/use-copy-to-clipboard/index.js @@ -13,8 +13,15 @@ import { useRef } from '@wordpress/element'; */ import useRefEffect from '../use-ref-effect'; -/** @typedef {import('@wordpress/element').RefObject} RefObject */ +/** + * @template T + * @typedef {import('react').RefObject} RefObject */ +/** + * @template T + * @param {T} value + * @return {import('react').RefObject} The updated ref + */ function useUpdatedRef( value ) { const ref = useRef( value ); ref.current = value; @@ -24,11 +31,11 @@ function useUpdatedRef( value ) { /** * Copies the given text to the clipboard when the element is clicked. * - * @param {text|Function} text The text to copy. Use a function if not + * @param {string | (() => string)} text The text to copy. Use a function if not * already available and expensive to compute. * @param {Function} onSuccess Called when to text is copied. * - * @return {RefObject} A ref to assign to the target element. + * @return {import('react').Ref} A ref to assign to the target element. */ export default function useCopyToClipboard( text, onSuccess ) { // Store the dependencies as refs and continuesly update them so they're @@ -37,11 +44,11 @@ export default function useCopyToClipboard( text, onSuccess ) { const onSuccesRef = useUpdatedRef( onSuccess ); return useRefEffect( ( node ) => { // Clipboard listens to click events. - const clipboard = new Clipboard( node, { + const clipboard = new Clipboard( /** @type {Element} */ ( node ), { text() { return typeof textRef.current === 'function' ? textRef.current() - : textRef.current; + : textRef.current || ''; }, } ); @@ -52,7 +59,7 @@ export default function useCopyToClipboard( text, onSuccess ) { clearSelection(); // Handle ClipboardJS focus bug, see // https://github.com/zenorocha/clipboard.js/issues/680 - node.focus(); + /** @type {HTMLElement} */ ( node ).focus(); if ( onSuccesRef.current ) { onSuccesRef.current(); diff --git a/packages/compose/src/hooks/use-ref-effect/index.js b/packages/compose/src/hooks/use-ref-effect/index.js index 26673a1ad4ddec..3c8c4f77d70cb5 100644 --- a/packages/compose/src/hooks/use-ref-effect/index.js +++ b/packages/compose/src/hooks/use-ref-effect/index.js @@ -17,14 +17,15 @@ import { useCallback, useRef } from '@wordpress/element'; * to be removed. It *is* necessary if you add dependencies because the ref * callback will be called multiple times for the same node. * - * @param {Function} callback Callback with ref as argument. - * @param {Array} dependencies Dependencies of the callback. + * @param {(node: Node) => (() => void) | undefined} callback Callback with ref as argument. + * @param {import('react').DependencyList} dependencies Dependencies of the callback. * - * @return {Function} Ref callback. + * @return {(node: Node) => void} Ref callback. */ export default function useRefEffect( callback, dependencies ) { + /** @type {import('react').MutableRefObject<(() => void) | undefined>} */ const cleanup = useRef(); - return useCallback( ( node ) => { + return useCallback( ( /** @type {Node} */ node ) => { if ( node ) { cleanup.current = callback( node ); } else if ( cleanup.current ) { diff --git a/packages/compose/tsconfig.json b/packages/compose/tsconfig.json index bf723fc3f3edaa..c94a7202dde65f 100644 --- a/packages/compose/tsconfig.json +++ b/packages/compose/tsconfig.json @@ -18,7 +18,10 @@ "src/hooks/use-async-list/**/*", "src/hooks/use-constrained-tabbing/**/*", "src/hooks/use-debounce/**/*", + "src/hooks/use-copy-on-click/**/*", + "src/hooks/use-copy-to-clipboard/**/*", "src/hooks/use-focus-return/**/*", + "src/hooks/use-ref-effect/**/*", "src/hooks/use-instance-id/**/*", "src/hooks/use-isomorphic-layout-effect/**/*", "src/hooks/use-keyboard-shortcut/**/*", From 2d617947405a7a49a08c14c39ec9d7b7524c45fe Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Mon, 17 May 2021 08:02:10 -0700 Subject: [PATCH 2/7] Use `RefCallback` type --- packages/compose/README.md | 2 +- packages/compose/src/hooks/use-ref-effect/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compose/README.md b/packages/compose/README.md index d477d414eba62f..20c75f76369fd9 100644 --- a/packages/compose/README.md +++ b/packages/compose/README.md @@ -403,7 +403,7 @@ _Parameters_ _Returns_ -- `(node: Node) => void`: Ref callback. +- `import('react').RefCallback`: Ref callback. # **useResizeObserver** diff --git a/packages/compose/src/hooks/use-ref-effect/index.js b/packages/compose/src/hooks/use-ref-effect/index.js index 3c8c4f77d70cb5..6118b1fb14518d 100644 --- a/packages/compose/src/hooks/use-ref-effect/index.js +++ b/packages/compose/src/hooks/use-ref-effect/index.js @@ -20,7 +20,7 @@ import { useCallback, useRef } from '@wordpress/element'; * @param {(node: Node) => (() => void) | undefined} callback Callback with ref as argument. * @param {import('react').DependencyList} dependencies Dependencies of the callback. * - * @return {(node: Node) => void} Ref callback. + * @return {import('react').RefCallback} Ref callback. */ export default function useRefEffect( callback, dependencies ) { /** @type {import('react').MutableRefObject<(() => void) | undefined>} */ From 508b1af75662dafe34a636276b0629a339a47fd9 Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Fri, 21 May 2021 08:13:40 -0700 Subject: [PATCH 3/7] Node can be null --- packages/compose/README.md | 2 +- packages/compose/src/hooks/use-ref-effect/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/compose/README.md b/packages/compose/README.md index 20c75f76369fd9..f4baffb5bdc36c 100644 --- a/packages/compose/README.md +++ b/packages/compose/README.md @@ -403,7 +403,7 @@ _Parameters_ _Returns_ -- `import('react').RefCallback`: Ref callback. +- `import('react').RefCallback`: Ref callback. # **useResizeObserver** diff --git a/packages/compose/src/hooks/use-ref-effect/index.js b/packages/compose/src/hooks/use-ref-effect/index.js index 6118b1fb14518d..3ad97d9990ebbe 100644 --- a/packages/compose/src/hooks/use-ref-effect/index.js +++ b/packages/compose/src/hooks/use-ref-effect/index.js @@ -20,12 +20,12 @@ import { useCallback, useRef } from '@wordpress/element'; * @param {(node: Node) => (() => void) | undefined} callback Callback with ref as argument. * @param {import('react').DependencyList} dependencies Dependencies of the callback. * - * @return {import('react').RefCallback} Ref callback. + * @return {import('react').RefCallback} Ref callback. */ export default function useRefEffect( callback, dependencies ) { /** @type {import('react').MutableRefObject<(() => void) | undefined>} */ const cleanup = useRef(); - return useCallback( ( /** @type {Node} */ node ) => { + return useCallback( ( /** @type {Node | null} */ node ) => { if ( node ) { cleanup.current = callback( node ); } else if ( cleanup.current ) { From b2ce994d7e033939ec5236daf839dab09ba4c833 Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Tue, 25 May 2021 06:25:51 -0700 Subject: [PATCH 4/7] Use HTMLElement for useRefCallback --- packages/compose/README.md | 6 +++--- .../src/hooks/use-copy-to-clipboard/index.js | 20 ++++++++----------- .../compose/src/hooks/use-ref-effect/index.js | 8 ++++---- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/compose/README.md b/packages/compose/README.md index f4baffb5bdc36c..5148c41ee855a4 100644 --- a/packages/compose/README.md +++ b/packages/compose/README.md @@ -185,7 +185,7 @@ _Parameters_ _Returns_ -- `import('react').Ref`: A ref to assign to the target element. +- `import('react').Ref`: A ref to assign to the target element. # **useDebounce** @@ -398,12 +398,12 @@ callback will be called multiple times for the same node. _Parameters_ -- _callback_ `(node: Node) => (() => void) | undefined`: Callback with ref as argument. +- _callback_ `(node: HTMLElement) => (() => void) | undefined`: Callback with ref as argument. - _dependencies_ `import('react').DependencyList`: Dependencies of the callback. _Returns_ -- `import('react').RefCallback`: Ref callback. +- `import('react').RefCallback`: Ref callback. # **useResizeObserver** diff --git a/packages/compose/src/hooks/use-copy-to-clipboard/index.js b/packages/compose/src/hooks/use-copy-to-clipboard/index.js index 9e9cb4f896e520..aee08641b9a87d 100644 --- a/packages/compose/src/hooks/use-copy-to-clipboard/index.js +++ b/packages/compose/src/hooks/use-copy-to-clipboard/index.js @@ -13,10 +13,6 @@ import { useRef } from '@wordpress/element'; */ import useRefEffect from '../use-ref-effect'; -/** - * @template T - * @typedef {import('react').RefObject} RefObject */ - /** * @template T * @param {T} value @@ -31,20 +27,20 @@ function useUpdatedRef( value ) { /** * Copies the given text to the clipboard when the element is clicked. * - * @param {string | (() => string)} text The text to copy. Use a function if not + * @param {string | (() => string)} text The text to copy. Use a function if not * already available and expensive to compute. - * @param {Function} onSuccess Called when to text is copied. + * @param {Function} onSuccess Called when to text is copied. * - * @return {import('react').Ref} A ref to assign to the target element. + * @return {import('react').Ref} A ref to assign to the target element. */ export default function useCopyToClipboard( text, onSuccess ) { // Store the dependencies as refs and continuesly update them so they're // fresh when the callback is called. const textRef = useUpdatedRef( text ); - const onSuccesRef = useUpdatedRef( onSuccess ); + const onSuccessRef = useUpdatedRef( onSuccess ); return useRefEffect( ( node ) => { // Clipboard listens to click events. - const clipboard = new Clipboard( /** @type {Element} */ ( node ), { + const clipboard = new Clipboard( node, { text() { return typeof textRef.current === 'function' ? textRef.current() @@ -59,10 +55,10 @@ export default function useCopyToClipboard( text, onSuccess ) { clearSelection(); // Handle ClipboardJS focus bug, see // https://github.com/zenorocha/clipboard.js/issues/680 - /** @type {HTMLElement} */ ( node ).focus(); + node.focus(); - if ( onSuccesRef.current ) { - onSuccesRef.current(); + if ( onSuccessRef.current ) { + onSuccessRef.current(); } } ); diff --git a/packages/compose/src/hooks/use-ref-effect/index.js b/packages/compose/src/hooks/use-ref-effect/index.js index 3ad97d9990ebbe..50de6a86e01cda 100644 --- a/packages/compose/src/hooks/use-ref-effect/index.js +++ b/packages/compose/src/hooks/use-ref-effect/index.js @@ -17,15 +17,15 @@ import { useCallback, useRef } from '@wordpress/element'; * to be removed. It *is* necessary if you add dependencies because the ref * callback will be called multiple times for the same node. * - * @param {(node: Node) => (() => void) | undefined} callback Callback with ref as argument. - * @param {import('react').DependencyList} dependencies Dependencies of the callback. + * @param {(node: HTMLElement) => (() => void) | undefined} callback Callback with ref as argument. + * @param {import('react').DependencyList} dependencies Dependencies of the callback. * - * @return {import('react').RefCallback} Ref callback. + * @return {import('react').RefCallback} Ref callback. */ export default function useRefEffect( callback, dependencies ) { /** @type {import('react').MutableRefObject<(() => void) | undefined>} */ const cleanup = useRef(); - return useCallback( ( /** @type {Node | null} */ node ) => { + return useCallback( ( /** @type {HTMLElement | null} */ node ) => { if ( node ) { cleanup.current = callback( node ); } else if ( cleanup.current ) { From 32e3c9469b8c1e7e0ef51b49e08f7cc8f95d3e06 Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Tue, 25 May 2021 06:39:26 -0700 Subject: [PATCH 5/7] compose: Make `useRefEffect` generic; also fix docgen for default exports --- packages/compose/README.md | 6 ++--- .../use-ref-effect/{index.js => index.ts} | 22 +++++++++++++------ packages/docgen/lib/get-type-annotation.js | 8 ++++++- 3 files changed, 25 insertions(+), 11 deletions(-) rename packages/compose/src/hooks/use-ref-effect/{index.js => index.ts} (64%) diff --git a/packages/compose/README.md b/packages/compose/README.md index 5148c41ee855a4..0166bc51d65aaf 100644 --- a/packages/compose/README.md +++ b/packages/compose/README.md @@ -398,12 +398,12 @@ callback will be called multiple times for the same node. _Parameters_ -- _callback_ `(node: HTMLElement) => (() => void) | undefined`: Callback with ref as argument. -- _dependencies_ `import('react').DependencyList`: Dependencies of the callback. +- _callback_ `( node: TElement ) => ( () => void ) | undefined`: Callback with ref as argument. +- _dependencies_ `DependencyList`: Dependencies of the callback. _Returns_ -- `import('react').RefCallback`: Ref callback. +- `RefCallback< TElement | null >`: Ref callback. # **useResizeObserver** diff --git a/packages/compose/src/hooks/use-ref-effect/index.js b/packages/compose/src/hooks/use-ref-effect/index.ts similarity index 64% rename from packages/compose/src/hooks/use-ref-effect/index.js rename to packages/compose/src/hooks/use-ref-effect/index.ts index 50de6a86e01cda..2b90c964e394ed 100644 --- a/packages/compose/src/hooks/use-ref-effect/index.js +++ b/packages/compose/src/hooks/use-ref-effect/index.ts @@ -1,3 +1,9 @@ +/** + * External dependencies + */ +// eslint-disable-next-line no-restricted-imports +import type { DependencyList, RefCallback } from 'react'; + /** * WordPress dependencies */ @@ -17,15 +23,17 @@ import { useCallback, useRef } from '@wordpress/element'; * to be removed. It *is* necessary if you add dependencies because the ref * callback will be called multiple times for the same node. * - * @param {(node: HTMLElement) => (() => void) | undefined} callback Callback with ref as argument. - * @param {import('react').DependencyList} dependencies Dependencies of the callback. + * @param callback Callback with ref as argument. + * @param dependencies Dependencies of the callback. * - * @return {import('react').RefCallback} Ref callback. + * @return Ref callback. */ -export default function useRefEffect( callback, dependencies ) { - /** @type {import('react').MutableRefObject<(() => void) | undefined>} */ - const cleanup = useRef(); - return useCallback( ( /** @type {HTMLElement | null} */ node ) => { +export default function useRefEffect< TElement = Node >( + callback: ( node: TElement ) => ( () => void ) | undefined, + dependencies: DependencyList +): RefCallback< TElement | null > { + const cleanup = useRef< ( () => void ) | undefined >(); + return useCallback( ( node: TElement | null ) => { if ( node ) { cleanup.current = callback( node ); } else if ( cleanup.current ) { diff --git a/packages/docgen/lib/get-type-annotation.js b/packages/docgen/lib/get-type-annotation.js index c6ef900fb2b87b..e3fc4a4f9529e8 100644 --- a/packages/docgen/lib/get-type-annotation.js +++ b/packages/docgen/lib/get-type-annotation.js @@ -43,7 +43,9 @@ function getFunctionTypeAnnotation( typeAnnotation, returnIndicator ) { typeAnnotation.typeAnnotation.typeAnnotation ); - return `( ${ params } )${ returnIndicator }${ returnType }`; + const paramsWithParens = params.length ? `( ${ params } )` : `()`; + + return `${ paramsWithParens }${ returnIndicator }${ returnType }`; } /** @@ -376,6 +378,10 @@ function getTypeAnnotation( typeAnnotation ) { */ function getFunctionToken( token ) { let resolvedToken = token; + if ( babelTypes.isExportDefaultDeclaration( resolvedToken ) ) { + resolvedToken = resolvedToken.declaration; + } + if ( babelTypes.isExportNamedDeclaration( resolvedToken ) ) { resolvedToken = resolvedToken.declaration; } From 1a4f6ef6837f8864b6e0e97dc74506ef4178ac1f Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Tue, 25 May 2021 06:41:40 -0700 Subject: [PATCH 6/7] Update CHANGELOG for docgen --- packages/docgen/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/docgen/CHANGELOG.md b/packages/docgen/CHANGELOG.md index 8e15f8ced64cf8..9f67b954644e18 100644 --- a/packages/docgen/CHANGELOG.md +++ b/packages/docgen/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Bug Fixes + +- Fix getting param annotations for default exported functions. ([#31603](https://github.com/WordPress/gutenberg/pull/31603)) + ## 1.17.0 (2021-04-29) ### New Features From 6f3c3ce72c08a824da115577cf0b9018367f1e08 Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Wed, 26 May 2021 08:00:35 -0700 Subject: [PATCH 7/7] Mark timeout as optional --- packages/compose/README.md | 2 +- packages/compose/src/hooks/use-copy-on-click/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compose/README.md b/packages/compose/README.md index 0166bc51d65aaf..258b0c9311e73c 100644 --- a/packages/compose/README.md +++ b/packages/compose/README.md @@ -168,7 +168,7 @@ _Parameters_ - _ref_ `import('react').RefObject>`: Reference with the element. - _text_ `string|Function`: The text to copy. -- _timeout_ `number`: Optional timeout to reset the returned state. 4 seconds by default. +- _timeout_ `[number]`: Optional timeout to reset the returned state. 4 seconds by default. _Returns_ diff --git a/packages/compose/src/hooks/use-copy-on-click/index.js b/packages/compose/src/hooks/use-copy-on-click/index.js index 99c595be99a202..238e2bc35573d8 100644 --- a/packages/compose/src/hooks/use-copy-on-click/index.js +++ b/packages/compose/src/hooks/use-copy-on-click/index.js @@ -17,7 +17,7 @@ import deprecated from '@wordpress/deprecated'; * * @param {import('react').RefObject>} ref Reference with the element. * @param {string|Function} text The text to copy. - * @param {number} timeout Optional timeout to reset the returned + * @param {number} [timeout] Optional timeout to reset the returned * state. 4 seconds by default. * * @return {boolean} Whether or not the text has been copied. Resets after the