Help when rendering a select
Unanswered
Alligator mississippiensis posted this in #help-forum
Alligator mississippiensisOP
I'm learning next and when I saw something about server actions, I was trying to use a server action in a select like this:
But I get the following error:
I don't know what I'm doing wrong or if I'm applying the server actions incorrectly. actions.
import { getDocentes } from "@/app/lib/services/ca/ca-admin-docente-asignatura";
import { Select, SelectItem } from '@nextui-org/react';
export default async function CreateForm() {
const docentes = await getDocentes();
return (
<div>
<form>
<div className="flex w-full flex-wrap md:flex-nowrap">
<Select label='Docentes' className="max-w-full" size='md'>
{docentes.map((item) => (
<SelectItem key={item.idDocente} value={item.idDocente}>
{item.Docente}
</SelectItem>
))}
</Select>
</div>
</form>
</div>
);
}But I get the following error:
Error: Unknown element <[object Object]> in collection.
at getFullNode.next (<anonymous>)
at iterateCollection.next (<anonymous>)
at Generator.next (<anonymous>)
digest: "640229397"
GET /dashboard/ca-admin-docente-asignatura/create 500 in 821msI don't know what I'm doing wrong or if I'm applying the server actions incorrectly. actions.
5 Replies
Nope @Alligator mississippiensis probably error happens while rendering
comment out <Select/> component part and debug to see error happens
also double check the respone type again
also double check the respone type again
@Alligator mississippiensis What you getting in response did u console log docentes?
@Shubham Tarpara <@1011775617567559680> What you getting in response did u console log docentes?
Alligator mississippiensisOP
Yes, I get a positive response from my server action. I try to put a select as is from html instead of using NextUI and that way it works, previously the data fetch was done in the same Select component of NextUI but everything from the client, however the project had to be changed to use server actions. I am new to using next and I would like to know which is the best way, using server actions or doing it from the client?
@Alligator mississippiensis Yes, I get a positive response from my server action. I try to put a select as is from html instead of using NextUI and that way it works, previously the data fetch was done in the same Select component of NextUI but everything from the client, however the project had to be changed to use server actions. I am new to using next and I would like to know which is the best way, using server actions or doing it from the client?
Spectacled bear
If it's just the render you can do it on the server side since it'll be faster providing better UX, but if you want user interactivity (eg. onChange, onClick) you have to use the client component, since there is no interactivity in server-side components.