-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compose: Add types to withInstanceId and corresponding hook (#31341)
* compose: Add types to withInstanceId and corresponding hook * Remove unused type * Fix types for underlying WeakMap * Rename to PropInjecting from PropRemoving
- Loading branch information
1 parent
94c985b
commit 5df4017
Showing
6 changed files
with
60 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
packages/compose/src/higher-order/with-instance-id/index.js
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
packages/compose/src/higher-order/with-instance-id/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
// eslint-disable-next-line no-restricted-imports | ||
import type { ComponentType } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import createHigherOrderComponent from '../../utils/create-higher-order-component'; | ||
// eslint-disable-next-line no-duplicate-imports | ||
import type { PropInjectingHigherOrderComponent } from '../../utils/create-higher-order-component'; | ||
import useInstanceId from '../../hooks/use-instance-id'; | ||
|
||
/** | ||
* A Higher Order Component used to be provide a unique instance ID by | ||
* component. | ||
*/ | ||
const withInstanceId: PropInjectingHigherOrderComponent< { | ||
instanceId: string | number; | ||
} > = createHigherOrderComponent( | ||
< TProps extends { instanceId: string | number } >( | ||
WrappedComponent: ComponentType< TProps > | ||
) => { | ||
return ( props: Omit< TProps, 'instanceId' > ) => { | ||
const instanceId = useInstanceId( WrappedComponent ); | ||
return ( | ||
<WrappedComponent | ||
{ ...( props as TProps ) } | ||
instanceId={ instanceId } | ||
/> | ||
); | ||
}; | ||
}, | ||
'withInstanceId' | ||
); | ||
|
||
export default withInstanceId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters