2.17 debugging is hard

3h Tonight I was up against a weird bug where I could only access an imported json object by hard-coding the elements I wanted. That wasn’t going to work for me, and I needed to find a better way. After I had spent 20 minutes writing it all out for a friend I finally tried something that helped me figure it out.

In my example data2.javascript came back with the right data, but data2[‘javascript’] would not. I needed to pass in a variable for the programming language so I had to use bracket notation and that meant I had to figure out why this wasn’t working for me.

To cut to the chase I still have no idea why it turned out this way, but I needed to address it like data2.default[‘javascript’] for it to work. Looking in the chrome debugger for hours on end helped me try that (as well as a lot of other failed tries)

I also ran into a lot of infinite reload loops in react because I was inadvertently calling an onclick handler when I was assigning it. It seems odd, but your onclick handler has to not have any arguments passed in, and it shouldn’t be run in the assignment. When it is actually run (ie a click happens) a click event is given to it as an argument. Luckily I was able to use the className in the click event in order to do what I needed to do.

Tell me what you think.

This site uses Akismet to reduce spam. Learn how your comment data is processed.