Next.js Discord

Discord Forum

Warning: Only plain objects can be passed to Client Components from Server Components

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
Hello, hope everyone is doing well. I am using next.js 14 app router. I have successfully integrated mongoDB database(local) with my nextjs project. But I am encountering a warining when toggle a button and send response to my mongoDB database. The warning is..
Warning: Only plain objects can be passed to Client Components from Server Components. Objects with toJSON methods are not supported. Convert it manually to a simple value before passing it to props. [{buffer: ...}]
here is my server actions:
async function toggleInterestedEvent(eventId, authId) { try { await updateInterest(eventId, authId); } catch (error) { throw error; } revalidatePath("/"); } export {toggleInterestedEvent}

NB: when I remove revalidatePath('/') from server actions then it doesn't shows any warning but when revalidatePath('/') exist it shows the warning.

and query functin to update database:

async function updateInterest(eventId, authId) { const event = await eventModel.findById(eventId); if (event) { const userIsFound = event.interested_ids.find( (id) => id.toString() === authId ); if (userIsFound) { event.interested_ids.pull(new mongoose.Types.ObjectId(authId)); } else { event.interested_ids.push(new mongoose.Types.ObjectId(authId)); } event.save(); } }

0 Replies