Created
October 28, 2018 12:46
-
-
Save morajabi/9cb38894efc6655013c8e2538b1a0508 to your computer and use it in GitHub Desktop.
Smart Gatsby Link
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
import * as React from 'react' | |
import { Link as GatsbyLink } from 'gatsby' | |
// Local | |
import { UnstyledButton } from './UnstyledButton' | |
type Props = { | |
/** For local gaysby routes/links */ | |
to?: string | |
/** For external links with e.g. https://google.com outside Gatsby */ | |
href?: string | |
children?: any | |
} | |
export const Link = ({ | |
to, | |
href, | |
children, | |
}: Props) => { | |
const Wrapper = to ? GatsbyLink : href ? 'a' : UnstyledButton | |
const props = to ? { to, ...rest } : href ? { href, ...rest } : { ...rest } | |
return <Wrapper {...props}>{children}</Wrapper> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment