Closed Mahider-Mengiste closed 2 years ago
The only line where you're using includes
here is this:
return recipe["recipeType"].includes(searchRecipes)
This means that recipe
does not have a property named recipeType
. I would suggest logging recipe
and making sure it looks the way you think it does.
Not all recipes have recipe type but some of the recipes that i want to have recipeType have recipeType
Uff, I hate it when data is inconsistent like that. You're going to have to test to see if it has that property first then with an if statement.
consider optional chaining
<myObject>?.<has-key?>
thanks, I was able to solve the problem. turns out i didn't have recipeType in my seed file.
What stack are you using?
(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)
MERN
What's the problem you're trying to solve?
I am trying to filter a recipe in the index page by a recipe type from my recipe API
Post any code you think might be relevant (one fenced block per file)
image for the link icons
Recipe Index - PART 1
continual for the index page - PART 2
Home.js
ShowJumboron component - this is where the icons are found
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
TypeError: Cannot read properties of undefined (reading 'includes')
What is your best guess as to the source of the problem?
well for starters, the props and state are defined and passed to the correct components. my best guess would be that either my clicks are not being targeted and passed to the state variable because, every time I click, what I am getting for that variable is null.
What things have you already tried to solve the problem?
I have tried to console.log everything and that is how i saw that i am getting null for my clicks. But the way my onClick function is set up looks right.
Paste a link to your repository here