When I use the state with the gatsby component Link that work when I do test with gatsby develop but failded with gatsby build with an error about undefined stuff. The error message show by the terminal is WebpackError: TypeError: Cannot read property 'info' of undefined I try to check for undefined by two differents ways but that's don't work. I cannot figure what I must do to solve that's problem.
first test :
if (!location.state.info) {
return null
} else
second test
if (typeof location.state.info === `undefined`) {
return null
} else
index page
import React from "react"
import { Link } from "gatsby"
import Layout from "../components/layout"
const IndexPage = () => (
<Layout>
<Link to="/page_test/" state={{ info: "test" }}>
Test
</Link>
</Layout>
)
export default IndexPage
page
import React from "react"
import { Link } from "gatsby"
const TestPage = ({ location }) => {
return <div>{location.state.info}</div>
}
export default TestPage