-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves the types of createHigherOrderComponent and its usages (#41138)
* createHOC: migrate default export to named * Evolve the types of createHigherOrderComponent and its usages * Fix index.native.js
- Loading branch information
Showing
12 changed files
with
121 additions
and
104 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
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
29 changes: 19 additions & 10 deletions
29
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 |
---|---|---|
@@ -1,21 +1,30 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import createHigherOrderComponent from '../../utils/create-higher-order-component'; | ||
import { | ||
createHigherOrderComponent, | ||
WithInjectedProps, | ||
WithoutInjectedProps, | ||
} from '../../utils/create-higher-order-component'; | ||
import useInstanceId from '../../hooks/use-instance-id'; | ||
|
||
type InstanceIdProps = { instanceId: string | number }; | ||
|
||
/** | ||
* A Higher Order Component used to be provide a unique instance ID by | ||
* component. | ||
*/ | ||
const withInstanceId = createHigherOrderComponent< { | ||
instanceId: string | number; | ||
} >( ( WrappedComponent ) => { | ||
return ( props ) => { | ||
const instanceId = useInstanceId( WrappedComponent ); | ||
// @ts-ignore | ||
return <WrappedComponent { ...props } instanceId={ instanceId } />; | ||
}; | ||
}, 'withInstanceId' ); | ||
const withInstanceId = createHigherOrderComponent( | ||
< C extends WithInjectedProps< C, InstanceIdProps > >( | ||
WrappedComponent: C | ||
) => { | ||
return ( props: WithoutInjectedProps< C, InstanceIdProps > ) => { | ||
const instanceId = useInstanceId( WrappedComponent ); | ||
// @ts-ignore | ||
return <WrappedComponent { ...props } instanceId={ instanceId } />; | ||
}; | ||
}, | ||
'instanceId' | ||
); | ||
|
||
export default withInstanceId; |
2 changes: 1 addition & 1 deletion
2
packages/compose/src/higher-order/with-preferred-color-scheme/index.native.js
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
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
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