dsfai2020 / Task-and-Nutrition-Manager

An agile planning application that tracks tasks, ideas and nutrition goals. This app is designed to assist with everyday productivity, progress tracking and fitness.
1 stars 0 forks source link

[RESOLVED] - Keys weren't displaying from If statement #67

Closed dsfai2020 closed 3 months ago

dsfai2020 commented 3 months ago

Describe the bug I created a condition that checks if a specific string is contained in the string value of the dictionary keys from local storage. I ran a console output to verify that the keys were correctly displaying. If I logged the local storage prior to the loop it would display the proper keys in my console output letting me know that the storage dictionary was accurate. But when I tried to narrow down my search criteria in an IF statement it wouldn't work. The highlight blue box was MISSING causing a full execution of all code that should've only been executing if the statements were true.

To Reproduce Steps to reproduce the behavior:

  1. Go to the same useEffect on the StoryUi.jsx file
  2. Click on the line of code containing the effect. Remove the { opening bracket directly after the if () statement as seen in the picture. View the browser to see the changes being executed in react. Press control+r in the browser to refresh the changes.
  3. Scroll down to the console output.
  4. See error that all of the keys are being printed instead of just the if statement conditional.

Expected behavior I expected only the keys containing 'uiBackEnd' to display. For example, if I had uiBackend1, uiBackEnd2, uiBackEnd3 etc... I would expect that the filter created with the if statement only return all of them because they all have uiBackEnd as a part of their key names. I wouldn't want it to return any other keys, related to other aspects.

Screenshots image

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context This issue was resolved PRIOR to posting it. I just wanted to add it for future reference. This took a lot of troubleshooting to make sure that the proper keys were being accessed to begin with. I wanted to isolate the problem so I created a unit test for it and knew that the science was working. I knew something had to be wrong with my code on the actual use case. I had tested different outputs to differentiate between the console variables. I used console.log error, info and debug to really isolate the text for easy verification. In the end it ended up being a simple overlook (of course after solving the code - the hard-part lol). It turns out I'd forgotten to include the { after the if (condition).