I am currently working on a basic NextJs TypeScript application with the app router.
The following code is functioning correctly:
export default async function Page() {
const res = await fetch("https://api.github.com/repos/vercel/next.js");
const data = await res.json();
return (
<>
<div>Hello from GetData</div>
<div>
<p>{data.id}</p>
</div>
</>
);
}
However, changing the API URL to the following stops it from working:
https://jsonplaceholder.typicode.com/posts/1 or any other API such as and https://jsonplaceholder.typicode.com/users
Moreover, I have implemented types for the endpoints to receive an array in response.
type User = {
id: number;
name: string;
};
const data: User[] = await res.json();
https://i.stack.imgur.com/uDWEs.png
Console error encountered:
https://i.stack.imgur.com/8dlTA.png
Browser error shown: