Working with React Components can get daunting at times especially with large codebases.
In this post, I鈥檓 sharing 3 bash commands that I use to make some of that work easier.
Let鈥檚 dive in!
#1: Find Components With Hardcoded Text
For easier debugging you might have harcoded some values in code.
But it鈥檚 always a good idea to get rid of them before productionization. As hard coding text makes localization difficult which becomes a barrier in globalizing the app.
You can use the following command to find hardcoded text, so that your app can support multiple languages:
grep -Er "['\"].*['\"]" src/**/*.jsx | grep -v 'i18n' | tee hardcoded_text.log
#2: identify Components Missing a Test File
Another command which i regularly use to debug low test coverage.
It鈥檚 to find what all components miss a test.
Use this command to list all react components that are missing a test file:
find src -name '*.jsx' | sed 's/.jsx$/.test.js/' | while read file; do [ ! -f "$file" ] && echo "Missing test: $file"; done
#3: Check Deprecated Lifecycle Methods
If you鈥檙e upgrading your React codebase to a new version, first problem you鈥檒l face is of deprecated lifecycle method.
Run the following bash command to proactively identify outdated code and smoother upgrades.
grep -Er '(componentWillMount|componentWillReceiveProps|componentWillUpdate)' src/**/*.jsx
And that鈥檚 it.
Hope you鈥檇 find these commands useful while working with React components.
Also, comment below which boring coding task are you procrastinating to automate?
Top comments (4)
Great stuff!
Glad you found it useful @miguelneto
that's really useful thanks
Thanks for reading @ozkanpakdil
Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more