Skip to content
Advertisement

React State seems to be overwritten / setState seems not to work

I am learning React and I think I am missing something fundamental with updating the state / rendering components.

JavaScript

The memory game has 5 cards at this point (just learning here) and depending on the memoryStatus it is determined if one side or other side is shown (true / false).

When clicked on a card I obviously want to change the value of that card in the array. I am doing that with this function:

JavaScript

The render part is:

JavaScript

Just in case it matters my data looks like this:

JavaScript

What am I doing wrong ??

Advertisement

Answer

setMemoryStatus is a function, thus you should be using parentheses () instead of brackets [] when calling it. The line to call it should be:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement