{"id":32048111,"url":"https://github.com/skullcrawler/react-env-secrets","last_synced_at":"2026-04-16T01:33:14.858Z","repository":{"id":308161273,"uuid":"1031816503","full_name":"SkullCrawler/react-env-secrets","owner":"SkullCrawler","description":"A zero-config React hook for environment variables - drop-in replacement for process.env","archived":false,"fork":false,"pushed_at":"2025-08-05T13:08:27.000Z","size":236,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-11T22:02:29.611Z","etag":null,"topics":["dotenv","env","environment-variables","process-env","react","react-hook","typescript","zero-config"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-env-secrets","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SkullCrawler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-04T11:26:17.000Z","updated_at":"2025-08-05T13:19:06.000Z","dependencies_parsed_at":"2025-08-04T16:55:17.806Z","dependency_job_id":null,"html_url":"https://github.com/SkullCrawler/react-env-secrets","commit_stats":null,"previous_names":["skullcrawler/react-env-secrets"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SkullCrawler/react-env-secrets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SkullCrawler%2Freact-env-secrets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SkullCrawler%2Freact-env-secrets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SkullCrawler%2Freact-env-secrets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SkullCrawler%2Freact-env-secrets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SkullCrawler","download_url":"https://codeload.github.com/SkullCrawler/react-env-secrets/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SkullCrawler%2Freact-env-secrets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31867711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotenv","env","environment-variables","process-env","react","react-hook","typescript","zero-config"],"created_at":"2025-10-18T00:41:32.441Z","updated_at":"2026-04-16T01:33:14.838Z","avatar_url":"https://github.com/SkullCrawler.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-env-secrets\n\n[![npm version](https://badge.fury.io/js/react-env-secrets.svg)](https://badge.fury.io/js/react-env-secrets)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)\n\n**A zero-configuration React hook for environment variables - the perfect drop-in replacement for `process.env`**\n\nStop writing `process.env.REACT_APP_SOMETHING` everywhere. Get clean, type-safe access to your environment variables with zero setup required.\n\n## ✨ Features\n\n- 🚀 **Zero Configuration** - Just install and use\n- 🔄 **Drop-in Replacement** - Replace `process.env.VARIABLE` with `useEnv()`\n- 🏷️ **TypeScript Support** - Full type safety out of the box\n- 🎯 **Smart Prefix Detection** - Works with React, Next.js, Vite, and more\n- 🧹 **Clean Variable Names** - No more prefixes in your code\n- ⚡ **Performance Optimized** - Cached for efficiency\n- 🛡️ **Error Handling** - Built-in validation and helpful error messages\n\n## 📦 Installation\n\n```bash\nnpm install react-env-secrets\n```\n\n```bash\nyarn add react-env-secrets\n```\n\n```bash\npnpm add react-env-secrets\n```\n\n## 🚀 Quick Start\n\n### Before (the old way):\n```tsx\nconst API_URL = process.env.REACT_APP_API_URL;\nconst PORT = process.env.REACT_APP_PORT;\nconst DATABASE_URL = process.env.REACT_APP_DATABASE_URL;\n\n// Lots of repetitive process.env.REACT_APP_ everywhere! 😫\n```\n\n### After (the clean way):\n```tsx\nimport { useEnv } from 'react-env-secrets';\n\nfunction MyComponent() {\n  const { API_URL, PORT, DATABASE_URL } = useEnv();\n  \n  return \u003cdiv\u003eAPI URL: {API_URL}\u003c/div\u003e;\n}\n```\n\nThat's it! No configuration needed. 🎉\n\n## 📝 Usage Examples\n\n### Basic Usage\n\n```tsx\nimport { useEnv } from 'react-env-secrets';\n\nfunction App() {\n  // Get all your environment variables at once\n  const { API_URL, PORT, DEBUG_MODE } = useEnv();\n  \n  return (\n    \u003cdiv\u003e\n      \u003ch1\u003eMy App\u003c/h1\u003e\n      \u003cp\u003eAPI: {API_URL}\u003c/p\u003e\n      \u003cp\u003ePort: {PORT}\u003c/p\u003e\n      \u003cp\u003eDebug: {DEBUG_MODE}\u003c/p\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n### With Validation \u0026 Fallbacks\n\n```tsx\nimport { useEnv } from 'react-env-secrets';\n\nfunction App() {\n  const env = useEnv({\n    required: ['API_URL', 'DATABASE_URL'], // Will show helpful errors if missing\n    fallbacks: {\n      PORT: '3000',\n      DEBUG_MODE: 'false'\n    }\n  });\n  \n  return \u003cdiv\u003eAPI: {env.API_URL}\u003c/div\u003e;\n}\n```\n\n### Single Variable Hook\n\n```tsx\nimport { useEnvVar } from 'react-env-secrets';\n\nfunction ApiComponent() {\n  const apiUrl = useEnvVar('API_URL', 'http://localhost:3000');\n  \n  return \u003cdiv\u003eConnecting to: {apiUrl}\u003c/div\u003e;\n}\n```\n\n### TypeScript Support\n\n```tsx\nimport { useEnv, type EnvVars } from 'react-env-secrets';\n\ninterface MyEnvVars extends EnvVars {\n  API_URL: string;\n  PORT: string;\n  DEBUG_MODE?: string;\n}\n\nfunction App() {\n  const { API_URL, PORT, DEBUG_MODE } = useEnv() as MyEnvVars;\n  // Full type safety! ✅\n}\n```\n\n## 🔧 Environment Setup\n\nCreate a `.env` file in your project root:\n\n```env\n# React apps\nREACT_APP_API_URL=https://api.example.com\nREACT_APP_PORT=3000\nREACT_APP_DEBUG_MODE=true\n\n# Next.js apps  \nNEXT_PUBLIC_API_URL=https://api.example.com\nNEXT_PUBLIC_PORT=3000\n\n# Vite apps\nVITE_API_URL=https://api.example.com\nVITE_PORT=3000\n\n# Or custom prefix\nPUBLIC_API_URL=https://api.example.com\n```\n\nThe hook automatically detects and strips these prefixes:\n- `REACT_APP_`\n- `NEXT_PUBLIC_`\n- `VITE_`\n- `PUBLIC_`\n\nSo `REACT_APP_API_URL` becomes just `API_URL` in your code! 🎯\n\n## 📚 API Reference\n\n### `useEnv(options?)`\n\nMain hook for accessing environment variables.\n\n**Parameters:**\n- `options` (optional): Configuration object\n  - `prefix?: string` - Custom prefix filter\n  - `required?: string[]` - Required variable names\n  - `fallbacks?: Record\u003cstring, string\u003e` - Fallback values\n\n**Returns:** Object with all environment variables\n\n### `useEnvVar(key, fallback?)`\n\nHook for a single environment variable.\n\n**Parameters:**\n- `key: string` - Variable name (without prefix)\n- `fallback?: string` - Fallback value\n\n**Returns:** Variable value or fallback\n\n### `clearEnvCache()`\n\nClears the internal cache. Useful for testing.\n\n### `listEnvVars()`\n\nDevelopment helper to see all available variables.\n\n## 🌟 Why react-env-secrets?\n\n### The Problem\n```tsx\n// This is what we're all tired of writing:\nconst API_URL = process.env.REACT_APP_API_URL;\nconst API_KEY = process.env.REACT_APP_API_KEY;\nconst PORT = process.env.REACT_APP_PORT || '3000';\nconst DEBUG = process.env.REACT_APP_DEBUG === 'true';\n\n// Repetitive, verbose, and error-prone! 😤\n```\n\n### The Solution\n```tsx\n// Clean, simple, and powerful:\nconst { API_URL, API_KEY, PORT, DEBUG } = useEnv({\n  fallbacks: { PORT: '3000' }\n});\n\n// That's it! 🚀\n```\n\n## 🔒 Security Features\n\n- **Client-Safe**: Only exposes prefixed environment variables on the client\n- **Server-Compatible**: Works seamlessly in server-side rendering\n- **Development Warnings**: Helpful error messages when variables are missing\n- **Type Safety**: Catch environment variable issues at compile time\n\n## 🏗️ Framework Support\n\nWorks perfectly with:\n\n- ✅ **Create React App**\n- ✅ **Next.js**\n- ✅ **Vite**\n- ✅ **Remix**\n- ✅ **Gatsby**\n- ✅ **Any React framework**\n\n## 🧪 Testing\n\n```tsx\nimport { clearEnvCache, listEnvVars } from 'react-env-secrets';\n\n// Clear cache between tests\nbeforeEach(() =\u003e {\n  clearEnvCache();\n});\n\n// See available variables in development\nconsole.log(listEnvVars());\n```\n\n## 🤝 Contributing\n\nWe welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.\n\n## 📄 License\n\nMIT © [Rayyan Waseem](https://github.com/SkullCrawler)\n\n## 🆘 Support\n\n- 📖 [Documentation](https://github.com/SkullCrawler/react-env-secrets#readme)\n- 🐛 [Issue Tracker](https://github.com/SkullCrawler/react-env-secrets/issues)\n- 💬 [Discussions](https://github.com/SkullCrawler/react-env-secrets/discussions)\n\n---\n\n**Made with ❤️ for React developers who are tired of `process.env.REACT_APP_EVERYTHING`**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskullcrawler%2Freact-env-secrets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskullcrawler%2Freact-env-secrets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskullcrawler%2Freact-env-secrets/lists"}