Replies: 1 comment
-
|
Hello! I see two ways of doing it. const Test = ({
data,
}: InferGetServerSidePropsType<typeof getServerSideProps>) => {
return <div>{data}</div>;
};
export async function getServerSideProps() {
const res: string = await fetch(`http://localhost:3000/api/hello`).then(
(res) => res.json()
);
return {
props: { data: res },
};
}and the other one simply share an interface: import { GetServerSidePropsResult } from "next";
interface Props {
data: string;
}
const Test = ({ data }: Props) => {
return <div>{data}</div>;
};
export async function getServerSideProps(): Promise<GetServerSidePropsResult<Props>> {
const res = await fetch(`http://localhost:3000/api/hello`).then(
(res) => res.json()
);
return {
props: { data: res },
};
}or even interface Props {
data: string;
}
const Test = ({ data }: Props) => {
return <div>{data}</div>;
};
export async function getServerSideProps() {
const res = await fetch(`http://localhost:3000/api/hello`).then(
(res) => res.json()
);
return {
props: { data: res } as Props,
};
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm new to typescript
and typescript is throwing this error on
Testwith the following code
Beta Was this translation helpful? Give feedback.
All reactions