相关疑难解决方法(0)

如何在 Next.js 中使用 props 输入页面组件?

我希望正确注释Home函数组件的参数,但遇到了一些麻烦。我希望将其注释为:{ events }: { events: Event[] },但收到 TypeScript 错误,Property 'events' does not exist on type '{ children: ReactNode }' in Next.js

接下来在幕后做了很多魔法,所以我不确定如何解决这个问题。有任何想法吗?

import type { NextPage } from 'next';
import { GetServerSideProps } from 'next';
import axios from '../lib/axios';

import { Event } from '../ts/interfaces';

const Home: NextPage = ({ events }) => {
  return (
    <div>
      {events.map((event: Event) => (
        <div key={event.title}>{event.title}</div>
      ))}
    </div>
  );
};

export const getServerSideProps: GetServerSideProps = async () …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs next.js

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

next.js ×1

reactjs ×1

typescript ×1