-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[No QA] [TS Migration] migrate withNavigation.js to TypeScript #29531
Changes from 2 commits
9ed2eaa
b646d2f
0017918
d841420
1c09561
6119982
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React, {ComponentType, ForwardedRef, RefAttributes} from 'react'; | ||
import {NavigationProp, useNavigation} from '@react-navigation/native'; | ||
import getComponentDisplayName from '../libs/getComponentDisplayName'; | ||
|
||
type WithNavigationProps = { | ||
navigation: NavigationProp<ReactNavigation.RootParamList>; | ||
}; | ||
|
||
export default function withNavigation<TProps extends WithNavigationProps, TRef>(WrappedComponent: ComponentType<TProps & RefAttributes<TRef>>) { | ||
function WithNavigation(props: Omit<TProps, keyof WithNavigationProps>, ref: ForwardedRef<TRef>) { | ||
const navigation = useNavigation(); | ||
return ( | ||
<WrappedComponent | ||
{...(props as TProps)} | ||
ref={ref} | ||
navigation={navigation} | ||
/> | ||
); | ||
} | ||
|
||
WithNavigation.displayName = `withNavigation(${getComponentDisplayName(WrappedComponent as ComponentType)})`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JKobrynski Maybe you can add same update to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
return React.forwardRef(WithNavigation); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add return type for this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!