Created
August 11, 2021 18:59
-
-
Save itaditya/1e736f1b94faaa752276feaab90edf87 to your computer and use it in GitHub Desktop.
Type checking params of CustomLink
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
interface Props<TParams> { | |
params: TParams, | |
path: string, | |
children: React.ReactChild, | |
} | |
const CustomLink = <TParams extends any>(props: Props<TParams>) => { | |
const { | |
path, | |
params, | |
children, | |
} = props; | |
console.log(path, params); | |
return ( | |
<div> | |
Hello {children} | |
</div> | |
) | |
} | |
const siteRouteParams = '/site/:siteId/page/:pageNumber'; | |
type SiteLinkParams = { | |
siteId: string, | |
pageNumber: number, | |
} | |
<> | |
<CustomLink<SiteLinkParams> | |
path={siteRouteParams} | |
params={{ siteId: 'netflix', page }} | |
> | |
Netflix | |
</CustomLink> | |
<CustomLink<SiteLinkParams> | |
path={siteRouteParams} | |
params={{ sitName: 'google', pageNumber: 2 }} | |
> | |
</CustomLink> | |
</> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment