I am currently facing an issue while trying to retrieve values using useStaticQuery
from my gatsby-config.js file. Below are snippets of my code.
Does anyone have any suggestions on how to resolve this problem?
Thank you in advance.
Repository:
https://github.com/koji/portfolio
package.json
"dependencies": {
"@babel/core": "^7.5.5",
"gatsby": "^2.13.28",
"gatsby-link": "^2.2.2",
"gatsby-plugin-react-helmet": "^3.1.2",
"gatsby-plugin-sass": "^2.1.3",
"gatsby-plugin-typescript": "^2.1.2",
"gatsby-source-filesystem": "^2.1.8",
"gatsby-source-instagram-all": "^2.0.5",
"gatsby-transformer-remark": "^2.6.10",
"node-sass": "^4.12.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"webpack": "^4.36.1"
},
"devDependencies": {
"@types/react": "^16.8.24",
"@types/react-dom": "^16.8.5",
"@types/react-helmet-async": "^1.0.0",
"env-cmd": "^9.0.3",
"eslint-plugin-react-hooks": "^1.6.1",
"gatsby-plugin-tslint": "^0.0.2",
"tslint": "^5.18.0",
"tslint-loader": "^3.5.4",
"tslint-react": "^4.0.0",
"typescript": "^3.5.3"
}
siteMetadata.ts
import { useStaticQuery, graphql } from "gatsby";
export const useSiteMetadata = () => {
const { site } = useStaticQuery(
graphql`
query {
site {
siteMetadata {
title
author
}
}
}
`);
return site.siteMetadata.title;
};
import * as React from "react";
import { useSiteMetadata } from 'siteMetadata'
export default class Header extends React.Component {
render() {
const {title} = useSiteMetadata();
return (
<h1>
<Link className={headerStyles.title} to="/">
{title}
</Link>
</h1>
)
}
}
gatsby-config.js
module.exports = {
siteMetadata: {
title: "page title",
author: "me"
}
}