'I can add a feedback object to an array of feedbacks using useContext/ useState, but I can't update any of them, how to do it?

I am working on a feedback app. The main page lists all feedbacks. If you klick "New Feedback" (on main page) a form opens and you can add a new feedback - it works, the new feedback will be added to feedbacks and show on the main page.

Now my struggles starts when I want to edit a feedback: (1) I klick on one of the feedbacks on main (2) It opens a form that is filled with the actual feedback properties (3) I edit the properties (4) I klick on "Edit feedback" which should update my feedback-array but it just doesn't work.

The data comes from a json file. The array of feedbacks ("productRequests" in data.json) are shared as "filteredItems/setFilteredItems" through useContext.

As a test I tried to overwrite my 10+ feedbacks-array with an array of 1 feedback, just to see if I can update it, but it turned into an error: "Cannot read properties of undefined (reading 'title') - which is so strange because this property was read perfectly fine when filling the form with the original feedback properties.

I tried splice method as well, got the same error.

I think I miss something very crucial about useContext and useState that is need to solve this. Could you help me out?

In my gist you find: addFeedback.js (works fine), data.js, editFeedback.js (my problem)

My gist



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source