20210903 - Set Environment Variables & Deal with missing dependencies
2021-09-03 00:00:00
Well, I’ve just known how to set environment variables.
- Create a .env (just the name ‘.env’ is fine) file in the root of your project
- In the file, add this line:
# env REACT_APP_API_KEY=[your_app_api_key]
- Add
const api_key = process.env.REACT_APP_API_KEY
to where you need the key - Hide your key by adding ‘.env’ file into gitignore, so that file wont be pushed to github, once you do commit
When every step was done, I did set the key and run the application successfully.
But here’s another error I got. I can’t figure out what it means:
react_devtools_backend.js:2850 src\components\Weather.js Line 22:6: React Hook useEffect has missing dependencies: ‘api_key’ and ‘profile.capital’. Either include them or remove the dependency array react-hooks/exhaustive-deps
Actually I remember I got this error last time and solved it finally. But this time it’s weird, like, why it had to mention api_key here? And what’s this dependency array exactly???
Solutions from stackoverflow, but I haven’t tested yet.
How to fix missing dependency warning when using useEffect React Hook