我习惯了以前的Next.js体系 struct ,并开始了一个新项目,try 将新体系 struct 与服务器和客户端组件结合使用.
我有一个页面,这是一个比赛结果表,需要在服务器上呈现的SEO目的.一旦页面加载,我想有一个过滤器输入字段,让用户找到他们正在寻找的运动员.
我对怎么做感到有点困惑,我觉得这是不可能的.我try 像以前的体系 struct 一样使用getServerSideProps
函数,但在新的体系 struct 上不起作用.
你知道怎么做吗?下面是我的页面代码的实际外观:
const RaceResultsPage = async ({ params }: { params: { raceId: string } }) => {
const result = await getResultByRaceId(+params.raceId);
return (
<>
<div>
{/* The input I want to use to filter the table*/}
<div className="relative mt-2 rounded-md shadow-sm">
<div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
<MagnifyingGlassIcon className="h-5 w-5 text-gray-400" aria-hidden="true" />
</div>
<input
type="email"
name="email"
id="email"
className="block w-full rounded-md border-0 py-1.5 pl-10 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
placeholder="Filtrer par nom, prénom, numéro, club"
/>
</div>
</div>
<div className="mt-8 flow-root">
<div className="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div className="inline-block min-w-full py-2 align-middle">
<table className="min-w-full divide-y divide-gray-300">
<thead>
<tr>
<th scope="col" className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
Pos.
</th>
<th scope="col" className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
Bib.
</th>
<th scope="col" className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
Nom
</th>
<th scope="col" className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
Cat
</th>
<th scope="col" className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
Temps
</th>
<th scope="col" className="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
Ecart
</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200 bg-white">
{result.map((person) => (
<tr key={person.bib}>
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{person.pos}</td>
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{person.bib}</td>
<td className="whitespace-nowrap px-3 py-4 text-sm font-medium text-gray-900">
{person.name}
</td>
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{person.catRank}</td>
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{person.totalTime}</td>
<td className="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{person.diff}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</>
);
};
我使用的是Next.js 14.