Next.js Discord

Discord Forum

Help when rendering a select

Unanswered
Alligator mississippiensis posted this in #help-forum
Open in Discord
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:
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 821ms

I 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
@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?