Im trying to get data from database with Prisma, but then those data has to be managed in some sort of state (compatible with app router).
component for fetching data:
import prisma from '@/prisma/client';
import React from 'react';
async function GetGamers() {
const gamers = await fetchGamers();
return (
gamers
);
}
async function fetchGamers() {
const gamers = await prisma.gamers.findMany();
return gamers;
}
export default GetGamers;```
component wrapping data as an option for select:
```import React from 'react';
import GetGamers from './GetGamers'
async function GamersList() {
const gamersJsx = await GetGamers();
return (
<>
{
gamersJsx.map((gamer) =>
(<option key={gamer.id}>{gamer.name}</option>))
}
</>
);
}
export default GamersList;```
component presenting data:
```import React from 'react';
import GamersList from './GamersList'
interface Gamer {
id: number;
lastTen: string;
mmr: number;
name: string;
server: string;
}
interface Gamers {
gamers: Gamer[];
}
function PickGamersBar() {
const gamersTable: string [] = new Array(10).fill({});
/
const gamersJSX = gamersTable.map((elem, index) =>
(
<select key={index}
className="select select-ghost select-bordered w-full max-w-xs flex flex-col space-y-4 text-white"
>
<option disabled selected>-Pick_Gamer-</option>
{/* @ts-expect-error Server Component */}
<GamersList/>
</select>
)
);
return (
<nav className="absolute left-0 right-0 p-4 h-3/4 flex flex-col justify-center">
<div className="container mx-auto ">
{gamersJSX}
</div>
</nav>
);
}
export default PickGamersBar;```
Now I want to make that picking a player with disable its choice in other selects.