DEV Community

Discussion on: Quick Introduction to React Custom Hooks With Dropdown Selection

Collapse
mejanhaque profile image
Muhammad Mejanul Haque

Thanks for mentioning the standard pattern. should the category value need to be null for fetching the uncategorized posts? and then should i try the categories.length method? I did set the category schema required true in mongoose & express.

when i fetch the category[0].title, it says title is undefined. I am using react hooks. other function worked perfectly. Thanks again for replying.

Thread Thread
vunderkind profile image
mogwai Author

Ah, seen!

Let's try debugging: Instead of fetching category[0].title, see if you can fetch category and either plant a debugger or log category to the console. We need to make sure the fetch is happening correctly, then check to see if the title key is present in the returned array object.

I suspect the problem is from the fetch in your hook, instead of in the assignment syntax afterward. Let me know what is returned from your API when you debug.