nextjs-course-code icon indicating copy to clipboard operation
nextjs-course-code copied to clipboard

Canot read properties of undefind (reading 'replace')

Open jirawatfreedom opened this issue 3 years ago • 5 comments

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 (

jirawatfreedom avatar Jan 11 '22 04:01 jirawatfreedom

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 props in your component.

fjerbi avatar Jan 16 '22 10:01 fjerbi

image

Same issue here, props passed in.

lukeryandev avatar Jan 18 '23 18:01 lukeryandev

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

lukeryandev avatar Jan 18 '23 18:01 lukeryandev

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.

jasdeepdhillon13 avatar May 03 '23 22:05 jasdeepdhillon13

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

Abdullah-encrypts avatar Aug 05 '23 19:08 Abdullah-encrypts