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

preview_player
Показать описание
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

#react #debugging #eslint #js #reactjs #javascript #webstylepress #webdevelopment #linting
Рекомендации по теме
Комментарии
Автор

Mine is giving in import styles at the starting

aryandennis
Автор

I created a navbar component and when i try to use it in the main app.js, i cant import the component...it says eslint error....and says component is declared but never used ....how to fix this issue

ajaybalakrishnan
Автор

my problem is name variable even i used it after declaring.

beulahkondaveeti
Автор

buit if i need the second one, and not the first?

joaovictormilhomem