Create a .env.local file.
- In Vite, using
.env.localautomatically ensures git ignores it unlike using.env - Add a variable for your api key
VITE_API_KEY=insert api key herein.env.local
/ * the VITE_ prefix is necessary for vite to to expose the api key in client */
// Example api keys in .env.local
VITE_API_KEY=09ej03918g0287h
VITE_RANDOM_KEY=168hnf18gy198ghy9
// Calling the api key in react
const apiKey = import.meta.env.VITE_API_KEY;