0

Hey I had a problem while using useContext (React Hooks) and useReducer (for store a array with 4 values of string). Explained in the pictures down below what exactly it's wrong and what I have done. Thank u

enter image description here App.js - using ItemsByCategory (Line 7). using useContext for passing for Categories component object with 2 values - CategoriesArray and CategoriesDisaptch (Line 37-39)enter image description here At categories component, I have a problem when adding the line of onClick function. Without it, works fine. The error that showed for me, added as an image. enter image description here

  • 1
    Can you please include the code instead of a picture? In my case I'm unable to see the images because imgur.com is blocked on my work machine. – CWSites Jan 29 '21 at 16:05

2 Answers2

0

The problem is that you are assigning CategoriesArray as categories in your <ItemsByCategory.Provider/>. So you have to do CategoriesContext.categories.map(filterCategory) instead.

Gh05d
  • 7,923
  • 7
  • 33
  • 64
0

find my problem. At reducer function can't do - return; I didn't want to update the categoriesArray - only want to display specific images according to their categories at setMenuItems function as I did - so return state in both cases. Added as a parameter for the func.