Trying to display page views with redis
Answered
Singapura posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
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.
I keep getting this error and then in my console getting an error with api/view/route on not being found.
![Image](https://cdn.discordapp.com/attachments/1150435355124842666/1150435355577823362/CleanShot_2023-09-10_at_10.18.412x.png)
![Image](https://cdn.discordapp.com/attachments/1150435355124842666/1150435356034990171/CleanShot_2023-09-10_at_10.19.132x.png)
Answered by risky
yeah make sure to use nextjs response
import { NextResponse } from 'next/server'
export async function GET() {
return NextResponse.json({ hello : "world"})
}
37 Replies
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
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](https://cdn.discordapp.com/embed/avatars/4.png)
SingapuraOP
Thx for replying, refactored it to separate the GET and POST methods into different functions, still getting the same error
![Image](https://cdn.discordapp.com/attachments/1150435355124842666/1150437617058455573/CleanShot_2023-09-10_at_10.27.112x.png)
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
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](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
@Singapura write return before res.json or res.status
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
yeah make sure to use nextjs response
import { NextResponse } from 'next/server'
export async function GET() {
return NextResponse.json({ hello : "world"})
}
Answer
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
SingapuraOP
Yup you're just right just show the total views like Rauch's blog (https://rauchg.com/)
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
@Singapura also use phind.com it will be way faster in helping
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
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](https://cdn.discordapp.com/embed/avatars/4.png)
SingapuraOP
Yes I've been using cursor.so with the latest nextjs 13 docs
Thx for the suggestion @Barbary Lion
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
Phind pulls lastest docs, doesn't usually hallucinate
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
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](https://cdn.discordapp.com/attachments/1150435355124842666/1150442685002424391/CleanShot_2023-09-10_at_10.47.232x.png)
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
where are you running the post req?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
Add console logs to see what code gets executed
In both methods
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
the code provided in second screenshot only shows them using get request, so im wondering where it gets incremented
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
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](https://cdn.discordapp.com/embed/avatars/4.png)
SingapuraOP
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
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](https://cdn.discordapp.com/embed/avatars/4.png)
SingapuraOP
Should I deploy it? I'm using upstash redis and it's showing in the dashboard that it's reading
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
i still don't see wher you are either calling the post req ore incremening it server side
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
SingapuraOP
It should be showing up here
![Image](https://cdn.discordapp.com/attachments/1150435355124842666/1150443694844031026/CleanShot_2023-09-10_at_10.52.152x.png)
Ok so that's probably the issue that the Post request to increment the views is not called anywhere
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
yeah
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
SingapuraOP
Ahhhhhhhh
thank you so much
Sorry for the questions transitioning from design to dev
It's working ðŸ™
![Image](https://cdn.discordapp.com/attachments/1150435355124842666/1150444488385364068/CleanShot_2023-09-10_at_10.55.322x.png)
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
yay!
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Barbary Lion
Are you making this thing by yourself
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
lol i didn't even relise that it was an ai product...
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
SingapuraOP
Lol nah getting some help from a friend
Mainly doing front-end/ux/sales
But trying to help where I can