Next.js Discord

Discord Forum

undefined data returned by map function

Answered
Otterhound posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by <Milind ツ />
use revalidatePath or revalidateTag just after u do router.push()
View full answer

49 Replies

Avatar
Otterhound
and i checked the data in postman and its returning
Image
Avatar
<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()
Avatar
Otterhound
no it don't show anything
Avatar
linesofcode
in your home page
console.log(data)
before returning
paste the result here
Avatar
<Milind ツ />
i am not sure why it wouldnt work for u. but ur exact code works for me
Avatar
Otterhound
should i make a new project
Avatar
<Milind ツ />
give it a try
Avatar
Otterhound
still didnot work
Avatar
<Milind ツ />
what version of node, nextjs u have?
Avatar
Otterhound
14
v20.9.0
Avatar
<Milind ツ />
hmm
try put the fetch inside a try catch and log the error
Avatar
Otterhound
still blank 😅
Avatar
<Milind ツ />
what browser u are using?
Avatar
Otterhound
edge
Avatar
<Milind ツ />
try other browser
chrome maybe
Avatar
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
<Milind ツ />
nah ignore that
thats from grammarly
otherwise setup a minimal repo and send link
Avatar
Otterhound
ok
Image
Avatar
<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
Otterhound
haha now its showing 😭
btw is app router new or
Avatar
<Milind ツ />
it is new. but has been there for months now
Avatar
Otterhound
should i continue with this or
Avatar
<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
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
<Milind ツ />
on local or prod?
Avatar
Otterhound
on local
can you check it
Image
Avatar
<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
Otterhound
i did that
   const res = await fetch("http://localhost:3000/api/products",{
        cache: "no-store",

      });
Avatar
<Milind ツ />
use revalidatePath or revalidateTag just after u do router.push()
Answer
Avatar
joulev
@Otterhound please do not delete the original question after it has been answered. Mark the answer instead.
Avatar
Otterhound
ahh sorry 😅