Debugging is a skill, not a talent test
Your button does nothing. The console shows an error, and your first instinct is to rewrite half the component. A better habit is to slow the process down and gather evidence. Debugging is the ability to form a hypothesis, test it and learn from the result.
Reproduce the bug Write down what you expected, what actually happened and the smallest set of steps that trigger the issue. If the bug only appears after a certain click sequence, record it. You cannot confidently fix a problem that you cannot reproduce.
Read the exact error Open your browser’s developer tools and check the Console. Note the file, line number and error message. A message about reading a property of undefined suggests a different investigation from an HTTP 404 or a syntax error. Read the whole error before searching for solutions.…