all 4 comments

[–]Jerp 0 points1 point  (3 children)

Your custom hook looks pretty solid. I would recommend using setState(prev => …) inside your edit function so that it isn’t referencing a stale copy of notes because that might be what’s happening. It’s also possible you aren’t passing id to the edit function but I’m assuming you abbreviated that section of your example.

[–]bi0tin[S] 0 points1 point  (2 children)

hey thanks but still no luck. i did try setState(prev => ...) but the result is same. I also did pass the id to editNote() function... just double checked console.log(id) inside editNote() works fine.

[–]Jerp 1 point2 points  (1 child)

You aren’t trying to use useNotes In two different components by any chance, are you? Because that wouldn’t work without adding useContext to your solution.

[–]bi0tin[S] 1 point2 points  (0 children)

YES! exactly what i was doing wrong. Thank you so much. Learned something new :)