Detected multiple renderers
Answered
Pacific sand lance posted this in #help-forum
Pacific sand lanceOP
I have some problems while trying to create a query in my PostgreSQL database with Prisma. Rather than adding the record it displayed an error "detected multiple renderers concurrently rendering the same context provider "
does anyone know what caused it?
I'm using Next.js 13.4.19, Prisma 5.3.1 and React 18.2
does anyone know what caused it?
I'm using Next.js 13.4.19, Prisma 5.3.1 and React 18.2
Answered by riský
// instead of:
const userData = JSON.parse(req.body)
// try:
const userData = await req.json()47 Replies
tbh you should always start with any bug by installing lates version (nextjs latest is
13.5.2)@riský tbh you should always start with any bug by installing lates version (nextjs latest is `13.5.2`)
Pacific sand lanceOP
how do i update to latest again?
i'm pretty new to this stuff
npm i next@latest for latest nextjs version@riský `npm i next@latest` for latest nextjs version
Pacific sand lanceOP
i will try, i'll give u updates on if it works or not
my data isn't showing up in prisma studio yet
@riský `npm i next@latest` for latest nextjs version
Pacific sand lanceOP
now it says
Compiled /not-foundas in, thats the error?
Pacific sand lanceOP
yeah
not displaying the detected multiple errors anymore
so its solved?
Pacific sand lanceOP
kind of, but the data didn't get created
might be something with my api routes
also try updating the others to latest if you havent' already
Pacific sand lanceOP
okay, i'll give any updates if something comes up
@Pacific sand lance okay, i'll give any updates if something comes up
have you gotten any other issues with this yet? (and solved the api routes issue?)
@riský have you gotten any other issues with this yet? (and solved the api routes issue?)
Pacific sand lanceOP
yeah it works now, i just need to change the file name to route.js since i'm using an app router
now i just have a PrismaClientValidationError
might just be something on how i send my queries
their [docs](https://www.prisma.io/docs/reference/api-reference/error-reference#prismaclientvalidationerror), make it sound like if you are doing the query but it isn't returning like expected
Prisma Client throws a PrismaClientValidationError exception if validation fails - for example:
- Missing field - for example, an empty data: {} property when creating a new record
- Incorrect field type provided (for example, setting a Boolean field to "Hello, I like cheese and gold!")
Pacific sand lanceOP
i'll share my code later i'm outside rn
but the message is that my argument is missing
@Pacific sand lance i'll share my code later i'm outside rn
yeah thats fine
@riský yeah thats fine
Pacific sand lanceOP
this is my code
// /app/pendaftaran/page.js
export default function Pendaftaran() {
const router = useRouter()
const [paketumrah, setPaketumrah] = useState("");
const [tipekamar, setTipekamar] = useState("");
const [namalengkap, setNamalengkap] = useState("");
const [nonik, setNonik] = useState("");
const [tempatlahir, setTempatlahir] = useState("");
const [tanggallahir, setTanggallahir] = useState("");
const [ayahkandung, setAyahkandung] = useState("");
const [nopaspor, setNopaspor] = useState("");
const [expirepaspor, setExpirepaspor] = useState("");
const [tempatpaspor, setTempatpaspor] = useState("");
const [pasporissued, setPasporissued] = useState("");
const [jeniskelamin, setJeniskelamin] = useState("");
const [golongandarah, setGolongandarah] = useState("");
const [statuskawin, setStatuskawin] = useState("");
const [namawaris, setNamawaris] = useState("");
const [hubunganwaris, setHubunganwaris] = useState("");
const [alamat, setAlamat] = useState("");
const [email, setEmail] = useState("");
const [notelponhp, setNotelponhp] = useState("");
const [pengalaman, setPengalaman] = useState("");
const [pendidikanterakhir, setPendidikanterakhir] = useState("");
const [pekerjaan, setPekerjaan] = useState("");
const [penyakit, setPenyakit] = useState("");
const [keluargadarurat, setKeluargadarurat] = useState("");const handleSubmit = async (event) => {
event.preventDefault()
try {
const userbody = {
paketumrah,
tipekamar,
namalengkap,
nonik,
tempatlahir,
tanggallahir,
ayahkandung,
nopaspor,
expirepaspor,
tempatpaspor,
pasporissued,
jeniskelamin,
golongandarah,
statuskawin,
namawaris,
hubunganwaris,
alamat,
email,
notelponhp,
pengalaman,
pendidikanterakhir,
pekerjaan,
penyakit,
keluargadarurat
}
await fetch('/api/submitdata', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(userbody)
})
router.push('/')
} catch (error) {
console.error(error)
}
}// /app/api/submitData/route.js
import { PrismaClient } from "@prisma/client";
import { NextResponse } from "next/server";
const prisma = new PrismaClient()
export async function POST(req) {
const userData = JSON.parse(req.body)
try {
const result = await prisma.user.create({
data: userData
})
return NextResponse.json({result}, {status: 200})
} catch (error) {
console.error(error)
return NextResponse.json({error}, {status: 500})
} finally {
await prisma.$disconnect() // Closing the PrismaClient instance
}
}oh that is alot of useStates
Pacific sand lanceOP
and the error
wait
⨯ SyntaxError: Unexpected token 'o', "[object Rea"... is not valid JSON
at JSON.parse (<anonymous>)
at POST (webpack-internal:///(rsc)/./app/api/submitdata/route.js:12:27)
at /home/lacri/Documents/code stuff/alharom/alharomapp/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:61472sorry if my code looks like a total beginner cuz that is what i am ðŸ˜
and also you should not disconect prisma instance and just create global one: https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices#solution
@Pacific sand lance sorry if my code looks like a total beginner cuz that is what i am ðŸ˜
// instead of:
const userData = JSON.parse(req.body)
// try:
const userData = await req.json()Answer
@riský ts
// instead of:
const userData = JSON.parse(req.body)
// try:
const userData = await req.json()
this is more important tho^
@Pacific sand lance is that all?
that was more of suggestion, not that it should break it (but it could)
Pacific sand lanceOP
alright lemme try it
@riský that was more of suggestion, not that it should break it (but it could)
Pacific sand lanceOP
it finally worked!
yay!!!
which message do you want to mark as solution?
@riský ts
// instead of:
const userData = JSON.parse(req.body)
// try:
const userData = await req.json()
Pacific sand lanceOP
this but i would recommend if working with a lot of data we should mark it like
const userData = await req.json()
...
data: {
name: userdata.name
...
}ahh like adding typings
Pacific sand lanceOP
yeap
thanks a lot btw!
no problem, glad to know that my following up actually helped 🙂 (decent amount people ignore me ;()
Pacific sand lanceOP
i should follow u on github