Here is the content of my index.tsx file:
import type { NextPage } from "next";
type AppProps = {
articles: {
userId: number;
id: number;
title: string;
body: string;
};
};
const Home: NextPage = ({articles}:AppProps) => {
return (
<div>
<h1>Welcome to {articles.title}</h1>
</div>
);
};
export const getStaticProps = async () => {
const res = await fetch('https://jsonplaceholder.typicode.com/posts/1')
const articles = await res.json();
return {
props: { articles },
};
};
export default Home;
Although the code renders, I encountered an error in my Home
component.
The error message displayed is as follows:
Type '({ articles }: AppProps) => JSX.Element' is not assignable to type 'NextPage<{}, {}>'.
Type '({ articles }: AppProps) => JSX.Element' is not assignable to type 'FunctionComponent<{}> & { getInitialProps?(context: NextPageContext): {} | Promise<{}>; }'.
Type '({ articles }: AppProps) => JSX.Element' is not assignable to type 'FunctionComponent<{}>'.
Types of parameters '__0' and 'props' are incompatible.
Property 'articles' is missing in type '{}' but required in type 'AppProps'.
I am unsure what I might be doing incorrectly. Any assistance would be greatly appreciated.