最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Remove unused conponents from ReactJS project - Stack Overflow

programmeradmin0浏览0评论

I have a React application, and a bunch of no-unused-vars in the console when running it getting me nuts, so I'm kindly asking you folks to share your experience: are there any such tools or no.

Screenshot of the console:

I have a React application, and a bunch of no-unused-vars in the console when running it getting me nuts, so I'm kindly asking you folks to share your experience: are there any such tools or no.

Screenshot of the console:

Share Improve this question edited Jun 5, 2021 at 11:36 Pawara Siriwardhane 2,05512 gold badges31 silver badges43 bronze badges asked Jun 5, 2021 at 11:07 ReginaTheMeanReginaTheMean 671 silver badge11 bronze badges 4
  • why not just go through and tidy up your code? If these are unused imports at the top of files, most IDEs will be able to 'organize imports' e.g. in webstorm it's ctrl + option + o – andy mccullough Commented Jun 5, 2021 at 11:19
  • First identify the file from where the unused variables occurs. Then ment them (if you want to keep them for future use) out or delete them. – dEBA M Commented Jun 5, 2021 at 11:27
  • Hello, Andy! The screenshot doesn't express the whole problem, there are hundreds of those ponents and I'm looking for a more convinient tool to remove all of those, not manually. + those unused variables aren;t imported from somewhere, they are declared in current react ponent, and I just don't use them. – ReginaTheMean Commented Jun 5, 2021 at 11:31
  • Hi, Deba! Thank you, I'm just looking forward if there is a tool that does everything instead of me, manually. – ReginaTheMean Commented Jun 5, 2021 at 11:34
Add a ment  | 

2 Answers 2

Reset to default 7

When projects get large its a pain to manage old code, what I did is to write a script to find unused exports (these will not be picked up by eslint) it should show you where you have a export that is not imported anywhere

just run:

npx dead-exports

assuming that your code is in ./src

read more here:

https://www.npmjs./package/dead-exports

Use vs code with and ES7 React/Redux/GraphQL/React-Native snippets proper code formatter like prettier and you will find unused ponents in different color as pared to used ponent

发布评论

评论列表(0)

  1. 暂无评论