'TypeError: Cannot destructure property 'siteSettingsData' of 'data' as it is undefined
TypeError: Cannot destructure property 'siteSettingsData' of 'data' as it is undefined.
Give this error when I'm going to pass data from a component but work fine on index page
import React from 'react'
import client from '../lib/sanity';
export default function Home({ data }) {
const { siteSettingsData } = data;
return (
<>
<h1 className="site-header__logo">{siteSettingsData.title}</h1>
</>
);
}
const siteSettingsQuery = `*[_type == "siteSettings"][0] {
title,
repoURL {
current
}
}`;
export async function getStaticProps() {
const siteSettingsData = await client.fetch(siteSettingsQuery);
const data = { siteSettingsData };
return {
props: {
data,
},
revalidate: 1,
};
}
Solution 1:[1]
Things you can do to solve the problem:
console.log(data)to see what you are receiving- Go to the file that is passing
propstoHome, to see whetherdatakey has been added. If it has, it should also include thesiteSettingsDatakey within thedata object.
More about props on the React website: https://reactjs.org/docs/components-and-props.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
