Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi, please i need help for resolving this error #6

Open
Kapelo256 opened this issue Dec 7, 2023 · 11 comments
Open

Hi, please i need help for resolving this error #6

Kapelo256 opened this issue Dec 7, 2023 · 11 comments

Comments

@Kapelo256
Copy link

⨯ src\app_components\Categories\index.tsx (18:28) @ map
⨯ TypeError: Cannot read properties of null (reading 'map')
at Categories (./src/app/_components/Categories/index.tsx:49:38)
at stringify ()
16 |
17 |

18 | {categories.map((category) => (
| ^
19 |
20 | ))}
21 |

@dikshyant3
Copy link

Provide the code snipped for it .from above error either the type for the categories is null or data is not loaded in your file.

@Kapelo256
Copy link
Author

Kapelo256 commented Dec 8, 2023 via email

@dikshyant3
Copy link

The error is because the categories prop is null. Make sure the categories prop is not null and check whether the error remains or not by adding below snippet during the map array function
{categories?.map((category) => (

))}

@Kapelo256
Copy link
Author

Kapelo256 commented Dec 9, 2023 via email

@dikshyant3
Copy link

The categories props comes from payload-types.ts make sure everything is correct there. The usage of optional chaining might resolve the issue which is {categories?.map((category) => ())}, if it doesn't then there might be another codebase which causes the error.

@Alain369
Copy link

I have the same problem. I tried two times two repeat the whole chapter but lways : ⨯ src/app/_components/Categories/index.tsx (17:21) @ map
⨯ TypeError: Cannot read properties of null (reading 'map')
at Categories (./src/app/_components/Categories/index.tsx:49:38)
at stringify ()
digest: "2181736854"
15 |


16 |

17 | {categories.map((category) => (
| ^
18 |
19 | ))}
20 |

At least the page will show when I add the ? like you said but this still wont give me any categories on my page

@Alain369
Copy link

So I found my mistake. I was missing the fourth closing curley bracket in the categories .ts in line 24. After adding it I got another error because of missing images in some category cards I created so I also added the question mark to line 22 from the categoryCard index.tsx to make the image optional: style={{ backgroundImage: url(${media?.url}) }}. Of course you don't necessarily want this when the product is running but it helps building before you got all your images together.

@Loyoenock
Copy link

I was facing the same challenge and followed the steps as provide above, now I have no error but the categories and images are not showing. Someone help me

@AngieProg
Copy link

I had the same problem. I was missing the last "t" letter in height world in the categories.ts
I recommende chechking the modified files in the category section:
src\payload\collections\Categories.ts
src\payload\payload-types.ts
src\app_graphql\products.ts
src\app_graphql\categories.ts
src\app_graphql\blocks.ts
src\app(pages)[slug]
src\app_api\fetchDocs
src\app_components\Categories

@Loyoenock
Copy link

Loyoenock commented Dec 16, 2023 via email

@Fernando-Ligabue
Copy link

Hello everyone, I also had a problem with this section, and after a few attempts, I discovered what was wrong with me.

In the (pages)[slug]page.tsx file, I needed to add the search for categories in the try/catch block.

In my specific case, after entering this data everything worked as expected.

   try {
     page = await fetchDoc<Page>({
       collection: 'pages',
       slug,
       draft: isDraftMode,
     })

     categories = await fetchDocs<Category>('categories')
   } catch (error) {
     console.error(error)
   }

I hope it helps anyone who is going through the same difficulty.

Best regards.

Thanks Adrian for another excellent tutorial.

Let's Code!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants