Created
January 1, 2020 16:21
-
-
Save dagda1/bd5c1a0b52539c92190f95637a2151c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export const RouteWrapper = function RouteWrapper< | |
P = { children?: ReactNode }, | |
TRoute extends RouteProps = Route | |
>( | |
Wrapper: React.ComponentType<P | {}>, | |
RouteType: React.ComponentType<RouteProps> = Route, | |
options: Partial<TRoute> = {}, | |
wrapperProps: P | {} = {}, | |
) { | |
return function RouteWrapperResuslt({ | |
component: RouteComponent, | |
path, | |
exact, | |
...rest | |
}: RouteWrapperProps<P, Partial<TRoute>>) { | |
return ( | |
<RouteType | |
path={path} | |
exact={exact} | |
{...options} | |
component={(props: P) => ( | |
<Wrapper {...(wrapperProps || {})}> | |
<RouteComponent {...rest} {...props} /> | |
</Wrapper> | |
)} | |
/> | |
); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment