An example of how to use Gatsby's StaticQuery with Typescript
This file contains 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 { graphql, StaticQuery } from 'gatsby'; | |
import * as React from 'react'; | |
interface HeaderProps { | |
className: string; | |
} | |
interface HeaderPropsWithData extends HeaderProps { | |
data: { | |
site: { | |
siteMetadata: { | |
title: string; | |
}, | |
}, | |
}; | |
} | |
const Header: React.SFC<HeaderPropsWithData> = ({ | |
className, | |
data, | |
}) => { | |
return ( | |
<header> | |
<h1 className={className}>{data.site.siteMetadata.title}</h1> | |
</header> | |
); | |
}; | |
export default (props: HeaderProps) => ( | |
<StaticQuery | |
query={graphql` | |
query { | |
site { | |
siteMetadata { | |
title | |
} | |
} | |
} | |
`} | |
// tslint:disable-next-line jsx-no-lambda | |
render={(data) => <Header data={data} {...props} />} | |
/> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment