Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Compo
Unanswered
David L. Bowman posted this in #help-forum
Often, after inserting/selecting an object from Drizzle ORM, I get this error. I understand I can
There's nothing here which looks like it's not a plain object:
JSON.stringify
, but then I lose my return types. Is there a better method here, where I can keep my intellisense? "use server";
import { db } from "@/lib/drizzle/db";
import {
exerciseDefinitions,
ExerciseType,
type ExerciseDefinitionsSelect,
} from "@/lib/drizzle/schemas/strength-training";
import { eq } from "drizzle-orm";
type SafeExerciseDefinition = Pick<
ExerciseDefinitionsSelect,
"id" | "name" | "type" | "primaryLiftDay"
>;
export async function getPrimaryExerciseDefinitions(): Promise<
SafeExerciseDefinition[]
> {
const primaryExercises = await db
.select()
.from(exerciseDefinitions)
.where(eq(exerciseDefinitions.type, ExerciseType.Primary));
const safeExercises = primaryExercises.map((exercise) => ({
id: exercise.id,
name: exercise.name,
type: exercise.type,
primaryLiftDay: exercise.primaryLiftDay,
}));
console.log("Safe exercises:", safeExercises);
return safeExercises;
}
There's nothing here which looks like it's not a plain object:
Safe exercises: [
{
id: 'ae965a8e-6f6b-4543-87f1-571852aa5776',
name: 'Squat',
type: 'primary',
primaryLiftDay: 'squat'
},
{
id: '6cccccd8-f776-4fa3-a6f0-7811cb16dbed',
name: 'Bench Press',
type: 'primary',
primaryLiftDay: 'bench'
},
{
id: 'b1bfa2fc-26b6-44a9-bb48-e8fa7909468e',
name: 'Deadlift',
type: 'primary',
primaryLiftDay: 'deadlift'
},
{
id: '3a59f956-b9b1-4018-a554-b1896e8e85e4',
name: 'Overhead Press',
type: 'primary',
primaryLiftDay: 'overhead'
}
]
1 Reply
nevermind... the issue was the code elsewhere T_T