I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
I find it challenging to resolve errors in my code. Without any problem, it shows this error even though everything is right. So error fixing is really difficult when it showing.
Is there any other way to solve this?
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
Ok, in the example you posted, eslint is telling you that you don't use something you explicitly imported. Why is it saying that if the code works? Well, it's because it's unnecessary and might be a sign that you overlooked something.
If I use a metaphor that's less car crashy, how about this:
Say you and your friend are going to buy food and drink for a party.
Your friend says, "I'll drive. Don't forget to bring the shopping list, your wallet, and a folding chair".
eslint at this point plays the part of your common sense - it says, "why are you telling me to bring a chair on a shopping trip? Is there something I should know?" And it won't get in the car until it has an answer.
So disabling eslint means accepting any weird thing your friend says at face value. What it wants you to do is to either say, "oh, I need to return that folding chair to the shop where I bought it", or "oops, I don't need the chair after all".
Extricating ourselves from my terrible metaphor, let's look at your code again:
You start with, import React from 'react'; but then you never use React anywhere in your code. You probably did this because you copied another React component and removed all the bits you didn't think you needed. That's a pretty common way to write code, btw, and nothing to feel bad about. So you can fix it by removing that line.
If you need to use the React object at some point in the future, you'll need to make sure you have that line to import it, but right now you don't. It's the folding chair in your shopping run.
Now, I'm guessing here, but I think the reason you haven't spotted this is because you think that a React component needs to have something magic happen to be counted as a React component, and unfortunately the build process for React (and most modern Javascript) is almost always set up so that a lot of things seem to happen by magic, so that's totally understandable. But a React component is just an object (or a class sometimes) loaded by something higher up the chain.
Does that make sense?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's like saying just cut the seatbelts out of your car if they feel a bit tight.
lol, better not to deal with eslint in the beggining
I find it challenging to resolve errors in my code. Without any problem, it shows this error even though everything is right. So error fixing is really difficult when it showing.
Is there any other way to solve this?
Ok, in the example you posted, eslint is telling you that you don't use something you explicitly imported. Why is it saying that if the code works? Well, it's because it's unnecessary and might be a sign that you overlooked something.
If I use a metaphor that's less car crashy, how about this:
Say you and your friend are going to buy food and drink for a party.
Your friend says, "I'll drive. Don't forget to bring the shopping list, your wallet, and a folding chair".
eslintat this point plays the part of your common sense - it says, "why are you telling me to bring a chair on a shopping trip? Is there something I should know?" And it won't get in the car until it has an answer.So disabling eslint means accepting any weird thing your friend says at face value. What it wants you to do is to either say, "oh, I need to return that folding chair to the shop where I bought it", or "oops, I don't need the chair after all".
Extricating ourselves from my terrible metaphor, let's look at your code again:
You start with,
import React from 'react';but then you never useReactanywhere in your code. You probably did this because you copied another React component and removed all the bits you didn't think you needed. That's a pretty common way to write code, btw, and nothing to feel bad about. So you can fix it by removing that line.If you need to use the React object at some point in the future, you'll need to make sure you have that line to import it, but right now you don't. It's the folding chair in your shopping run.
Now, I'm guessing here, but I think the reason you haven't spotted this is because you think that a React component needs to have something magic happen to be counted as a React component, and unfortunately the build process for React (and most modern Javascript) is almost always set up so that a lot of things seem to happen by magic, so that's totally understandable. But a React component is just an object (or a class sometimes) loaded by something higher up the chain.
Does that make sense?