I have the problem in importing the header file in the React app file, once I try to import it gives me this message "’Header’ is defined but never used." please help me, for the one who is familiar with react.js . Also how can I solve this problem easily once I come across this problem or another problem similar to this?
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
2
Answers
If the particular import is not used in any way, an additional imports within that component will also be brought in. This means there might be unused imports, like Header, within your components. Take a thorough look through all your components and remove any unnecessary Header imports. It won’t impact your application’s functionality, but it’ll tidy up your codebase.
If you would like to use the Header Component, I would suggest you to include the component inside the App Component. I have included the code snippet below.
What you are seeing is not an error but a waring message that you imported a component ‘Header’ which is defined (as you have exported it correctly) but it is not being used on your app file. Here’s the code example to fix this –
Once you add Header component inside the return statement of app.js, you will be able to see your Header component render on browser also the warning will be gone.