Next.js Discord

Discord Forum

Trying to display page views with redis

Answered
Singapura posted this in #help-forum
Open in Discord
Avatar
SingapuraOP
"Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported."

I keep getting this error and then in my console getting an error with api/view/route on not being found.
Image
Image
Answered by Risky
yeah make sure to use nextjs response
import { NextResponse } from 'next/server'
 
export async function GET() {
  return NextResponse.json({ hello : "world"})
}
View full answer

37 Replies

Avatar
Risky
you should simplify your code, and make seperate functions for the diferent methods: https://nextjs.org/docs/app/building-your-application/routing/route-handlers#convention
i don't think you can just export handler like that...
Avatar
SingapuraOP
Thx for replying, refactored it to separate the GET and POST methods into different functions, still getting the same error
Image
Avatar
Risky
you request it as POST or GET /api/view (no /route is needed)
also, im assuming you don't want it to increment on the footer, and just show the amount of views
Avatar
Barbary Lion
@Singapura write return before res.json or res.status
Avatar
Risky
yeah make sure to use nextjs response
import { NextResponse } from 'next/server'
 
export async function GET() {
  return NextResponse.json({ hello : "world"})
}
Answer
Avatar
SingapuraOP
Yup you're just right just show the total views like Rauch's blog (https://rauchg.com/)
Avatar
Barbary Lion
@Singapura also use phind.com it will be way faster in helping
Avatar
Risky
pls don't recommend AI, if you want to, at least use #gpt-help because nextjs team trusts it and makes sure its trained on latest docs
Avatar
SingapuraOP
Yes I've been using cursor.so with the latest nextjs 13 docs
Thx for the suggestion @Barbary Lion
Avatar
Barbary Lion
Phind pulls lastest docs, doesn't usually hallucinate
Avatar
SingapuraOP
I'll check it out, let me modify it with the nextjs response first
I'm not getting any errors but the views aren't updating at every refresh
Image
Avatar
Risky
where are you running the post req?
Avatar
Barbary Lion
Add console logs to see what code gets executed
In both methods
Avatar
Risky
the code provided in second screenshot only shows them using get request, so im wondering where it gets incremented
Avatar
Barbary Lion
Also is redis locally hosted? You can't do that with a edge function. Try using a service that hosts a redis instance for you
Avatar
SingapuraOP
Avatar
Risky
can we also pls not assume more than nessary... not all devs want to use vercel... a decent amount want to self host, where redis is good + they could be connecting to serverless redis host anyway
Avatar
SingapuraOP
Should I deploy it? I'm using upstash redis and it's showing in the dashboard that it's reading
Avatar
Risky
i still don't see wher you are either calling the post req ore incremening it server side
Avatar
SingapuraOP
It should be showing up here
Image
Ok so that's probably the issue that the Post request to increment the views is not called anywhere
Avatar
Risky
yeah
Avatar
SingapuraOP
Ahhhhhhhh
thank you so much
Sorry for the questions transitioning from design to dev
It's working 🙏
Image
Avatar
Risky
yay!
Avatar
Barbary Lion
Are you making this thing by yourself
Avatar
Risky
lol i didn't even relise that it was an ai product...
Avatar
SingapuraOP
Lol nah getting some help from a friend
Mainly doing front-end/ux/sales
But trying to help where I can