Im not getting my data (notes) inside the props, it is giving undefined when im using console.log(notes). My backend api is also in the same project in /pages/api/notes/index.js The api which im calling is ‘http://localhost:3000/api/notes’
Even my api is working fine when im testing it on postman. But on the frontend, data isnt available
Please checkout this issue.
Advertisement
Answer
I believe that you simply have a typo. Index.getinitialProps
should be Index.getInitialProps
. Note that the “i” in initial is capitalized.
Also as a tip, you don’t explicitly need http://localhost:3000
, if you just call it with /api/notes
it will correctly resolve the request. That way when you deploy the app you don’t have to go back and make a ton of changes for your data fetches.