mschwarzmueller / nextjs-course-code

Source code for my NextJS course (https://acad.link/nextjs)
1.43k stars 2.32k forks source link

Canot read properties of undefind (reading 'replace') #18

Open jirawatfreedom opened 2 years ago

jirawatfreedom commented 2 years ago

error - components\events\event-item.js (17:36) @ EventItem TypeError: Cannot read properties of undefined (reading 'replace') 15 | year: 'numeric', 16 | });

17 | const formattedAddress = location.replace(', ', '\n');
| ^ 18 | const exploreLink = /events/${id}; 19 | 20 | return (

fjerbi commented 2 years ago

That Error message means that he couldn't access the location prop. Are you passing location as a prop? you should have this : const { title, image, date, location, id } = props; In the beginning of your component. and do not forget to pass propsin your component.

lukeryandev commented 1 year ago
image

Same issue here, props passed in.

lukeryandev commented 1 year ago

I also added an optional chain, this is what displays when the formatting is skipped: EDIT: Same result when String(location) is applied.

const formattedAddress = location?.replace(", ", "\n");

image
jasdeepdhillon13 commented 1 year ago

In some cases, this issue can be caused by not changing the firebase url in the api-utils.js file, which is set to point to the firebase by max. You should either replace the firebase url in the response variable to your own firebase url.

Abdullah-encrypts commented 11 months ago

In some cases, this issue can be caused by not changing the firebase url in the api-utils.js file, which is set to point to the firebase by max. You should either replace the firebase url in the response variable to your own firebase url.

Yup when i was in that module i had the same issue and it was being caused by the firebase url