I have a Grid of which every cell accesses an update function onClick to mark the cell as clicked. During to the fact that I need to access the data of which cells are clicked later somewhere else I created a Context. I noticed the performance is getting very bad with a huge grid I wanted to minimize rerenders and wrapped the Cell Component called Node in useMemo so that it only rerenders if the className changes which colors the cell yellow if clicked. My Problem is that if I click on one cell it gets colored yellow but as I click on a second Cell the state Hook in the stateContexts.js doesnt remember the first clicked cell. If someone knows how to solve that I would be very thankful.
Here is codesandbox link: https://codesandbox.io/s/jovial-nobel-i1lg4