Assigned a Value but Never Used | No Unused Vars | React JS Debugging | Eslint Warnings & Errors

Assigned a Value but Never Used | No Unused Vars | React JS Debugging | Eslint Warnings & Errors


Assigned a Value but Never Used | No Unused Vars | React JS Debugging | Eslint Warnings & Errors

In react component I want to display a name but I want to read it from the app state. This name will not be changed but it can pass along to multiple components down the line. I used useState hook to implement state in react app. When I run this app, it gives me warning in console, in visual studio output window and when I hover over setName variable, I see same warning message.

setName is declared but its value is never read. setName is assigned a value but never used, eslint, no unused vars. This warning is related to eslint code linter. eslint helps me write better code and checks errors and warnings, it lets me know about the error or warnings before code runs. State is being used in react app but it will not change so setState is useless here and we can safely remove that.

Warning is gone when I removed the setName. The app is working fine. So remove variables that are not being used in your app.

Thank You!
👍 LIKE VIDEO
👊 SUBSCRIBE
🔔 PRESS BELL ICON
✍️ COMMENT

Channel:    / webstylepress  
Website: https://www.webstylepress.com
FaceBook: https://www.facebook.com/webstylepress
Twitter: https://twitter.com/webstylepress
GitHub: https://github.com/webstylepress
#react #debugging #eslint #js #reactjs #javascript #webstylepress #webdevelopment #linting


Content

6.08 -> Welcome to webstylepress. In this react  component I want to display a name  
10.96 -> but I want to read it from state. This name  will not be changed but it can pass along to  
17.12 -> multiple components down the line this  is the output for the app. let, import,
27.84 -> use state, from react,
35.92 -> and use it here
51.84 -> so
61.76 -> and here is the same output so we see a warning  sign here and as you can see this set Name is  
70.56 -> declared but its value is never read setName  is assigned a value but never used eslint, no  
80 -> unused vars, if i look into the console i see this  message here as well setName is assigned a value  
87.92 -> but never used, no unused vars, also from visual  studio code i see this warning from here as well  
99.68 -> same warning message eslint no unused vars
109.92 -> this warning is related to eslint,  eslint helps me to write better code  
115.44 -> and checks errors and warnings, it lets  me know about the error before code runs,  
122.32 -> state is being used but it will not change so this  thing is useless here, we can safely remove that
133.28 -> and now the warning is gone also  warning is gone from console  
140 -> and the app is working fine so there you go remove  variables that are not being used in your app.  
148 -> alright, like, share, subscribe and  i will see you in the next video

Source: https://www.youtube.com/watch?v=3_4QlPxuEK4