undefined data returned by map function
Answered
Otterhound posted this in #help-forum
Original message was deleted.
Answered by <Milind ツ />
use revalidatePath or revalidateTag just after u do router.push()
49 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
and i checked the data in postman and its returning
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
You are logging data in getStaticProps so does the data show in your ide console?
When receiving the data prop in homepage, so before returning the jsx, try to log the data before.
If the data is there,
try to check if the data coming as an object and see if it can be destructured using Object.entries()
When receiving the data prop in homepage, so before returning the jsx, try to log the data before.
If the data is there,
try to check if the data coming as an object and see if it can be destructured using Object.entries()
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
no it don't show anything
![Avatar](https://cdn.discordapp.com/avatars/414145877335080960/c7ab639b9f825e9f8db0ed902b831f2b.webp?size=256)
linesofcode
in your home page
console.log(data)
before returning
paste the result here
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
i am not sure why it wouldnt work for u. but ur exact code works for me
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
should i make a new project
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
give it a try
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
still didnot work
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
what version of node, nextjs u have?
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
14
v20.9.0
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
hmm
try put the fetch inside a try catch and log the error
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
still blank 😅
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
what browser u are using?
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
edge
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
try other browser
chrome maybe
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
i got this error in console rning: Extra attributes from the server: data-new-gr-c-s-check-loaded,data-gr-ext-installed
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
nah ignore that
thats from grammarly
otherwise setup a minimal repo and send link
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
ok
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
bro u are using app router.
data fetching methods for app router is different
normal pages router methods dont work on app router
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
haha now its showing ðŸ˜
btw is app router new or
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
it is new. but has been there for months now
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
should i continue with this or
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
many old docs still mention and provide examples for pages router and hence this creates a confusion.
this depends from project to project
if you arent/wont be using any package that does not work/has issues with app router, you would use pages router. else app router is good to go
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
oh ok hey i want one more help so i did crud app and everything is working but i have to hard reload to see changes in browser
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
on local or prod?
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
on local
can you check it
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
you have to provide more details on how you are handling the CRUD operations.
like say if you are adding a product, so when navigating back to home. You have to make sure you revalidate the home path. when u do router.push("/"). do revalidate along with it.
you can check up revalidation on nextjs from same link above
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
i did that
const res = await fetch("http://localhost:3000/api/products",{
cache: "no-store",
});
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
use revalidatePath or revalidateTag just after u do router.push()
Answer
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
@Otterhound please do not delete the original question after it has been answered. Mark the answer instead.
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Otterhound
ahh sorry 😅