Skip to content

Commit f38f718

Browse files
committed
fix deploy
1 parent f0367d4 commit f38f718

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pages/api-example.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { GetServerSideProps } from 'next';
22
import React from 'react';
33

4-
const ApiExample: React.FC<{ data: any; error: string | null }> = ({ data, error }) => {
4+
interface ApiData {
5+
title: string;
6+
body: string;
7+
}
8+
9+
interface ApiExampleProps {
10+
data: ApiData | null;
11+
error: string | null;
12+
}
13+
14+
const ApiExample: React.FC<ApiExampleProps> = ({ data, error }) => {
515
if (error) {
616
return <div>Error: {error}</div>;
717
}
@@ -17,13 +27,13 @@ const ApiExample: React.FC<{ data: any; error: string | null }> = ({ data, error
1727
);
1828
};
1929

20-
export const getServerSideProps: GetServerSideProps = async () => {
30+
export const getServerSideProps: GetServerSideProps<ApiExampleProps> = async () => {
2131
try {
2232
const response = await fetch('https://jsonplaceholder.typicode.com/posts/1');
2333
if (!response.ok) {
2434
throw new Error('Failed to fetch data');
2535
}
26-
const jsonData = await response.json();
36+
const jsonData: ApiData = await response.json();
2737
return {
2838
props: {
2939
data: jsonData,
@@ -34,7 +44,7 @@ export const getServerSideProps: GetServerSideProps = async () => {
3444
return {
3545
props: {
3646
data: null,
37-
error: error.message,
47+
error: error instanceof Error ? error.message : 'Unknown error',
3848
},
3949
};
4050
}

0 commit comments

Comments
 (0)