Skip to content

Instantly share code, notes, and snippets.

@dagda1
Created January 1, 2020 16:21
Show Gist options
  • Save dagda1/bd5c1a0b52539c92190f95637a2151c7 to your computer and use it in GitHub Desktop.
Save dagda1/bd5c1a0b52539c92190f95637a2151c7 to your computer and use it in GitHub Desktop.
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