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
Otterhound
and i checked the data in postman and its returning
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()
Otterhound
no it don't show anything
i am not sure why it wouldnt work for u. but ur exact code works for me
Otterhound
should i make a new project
give it a try
Otterhound
still didnot work
what version of node, nextjs u have?
Otterhound
14
v20.9.0
hmm
try put the fetch inside a try catch and log the error
Otterhound
still blank 😅
what browser u are using?
Otterhound
edge
try other browser
chrome maybe
Otterhound
i got this error in console rning: Extra attributes from the server: data-new-gr-c-s-check-loaded,data-gr-ext-installed
Otterhound
ok
bro u are using app router.
data fetching methods for app router is different
normal pages router methods dont work on app router
Otterhound
haha now its showing ðŸ˜
btw is app router new or
it is new. but has been there for months now
Otterhound
should i continue with this or
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
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
on local or prod?
Otterhound
on local
can you check it
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
Otterhound
i did that
const res = await fetch("http://localhost:3000/api/products",{
cache: "no-store",
});
use revalidatePath or revalidateTag just after u do router.push()
Answer
@Otterhound please do not delete the original question after it has been answered. Mark the answer instead.
Otterhound
ahh sorry 😅