{"id":26178681,"url":"https://github.com/loadsmart/react-frontend-settings","last_synced_at":"2025-06-14T17:38:16.617Z","repository":{"id":46410400,"uuid":"382458162","full_name":"loadsmart/react-frontend-settings","owner":"loadsmart","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-31T18:09:10.000Z","size":323,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":59,"default_branch":"main","last_synced_at":"2025-05-26T19:49:22.286Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loadsmart.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-02T20:35:27.000Z","updated_at":"2021-10-15T21:52:11.000Z","dependencies_parsed_at":"2024-10-23T13:54:46.409Z","dependency_job_id":null,"html_url":"https://github.com/loadsmart/react-frontend-settings","commit_stats":{"total_commits":55,"total_committers":6,"mean_commits":9.166666666666666,"dds":0.4727272727272728,"last_synced_commit":"eef7505e996c214cbd5115a9120f31b9a9f4173b"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsmart%2Freact-frontend-settings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsmart%2Freact-frontend-settings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsmart%2Freact-frontend-settings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsmart%2Freact-frontend-settings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loadsmart","download_url":"https://codeload.github.com/loadsmart/react-frontend-settings/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsmart%2Freact-frontend-settings/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258461736,"owners_count":22705002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-03-11T21:42:06.294Z","updated_at":"2025-06-14T17:38:16.579Z","avatar_url":"https://github.com/loadsmart.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Frontend Settings\n\nDynamic frontend settings for React applications.\n\nThis application is meant to be used together with [django-frontend-settings](https://github.com/loadsmart/django-frontend-settings)\nor some other settings provider. The most important part is that the `getSettings` function must return a `Promise` which will resolve\nto a json object like:\n\n```json\n{\n  \"settings\": {\n    \"GOOGLE_MAPS_KEY\": \"abcd1234\",\n    \"SOME_OTHER_SETTING\": 123\n  },\n  \"flags\": {\n    \"ENABLE_FEATURE_AAA\": true,\n    \"ENABLE_FEATURE_BBB\": false\n  }\n}\n```\n\n## Usage/Examples\n\nYou will need to wrap your application with the `SettingsProvider` component, like this:\n\n```javascript\nimport { SettingsProvider } from '@loadsmart/react-frontend-settings'\n\nfunction getSettings() {\n  return http.get('/api/frontend-settings')\n}\n\nfunction App() {\n  return (\n      \u003cSettingsProvider getSettings={getSettings}\u003e\n        \u003cThemeProvider theme={myTheme}\u003e\n        \u003cSuspense fallback={\u003cp\u003eLoading\u003c/p\u003e}\u003e\n          {/* ... */}\n        \u003c/Suspense\u003e\n      \u003c/SettingsProvider\u003e\n  )\n}\n```\n\nThe provider accepts options as well:\n\n- updateIntervalMs: the interval to refetch the settings in ms, default: 10 minutes.\n- onGetSettingsFail: how to handle an error when fetching the settings, accepts two values:\n  - `keep-last`: if the request fail, keep the last known value.\n  - `reset`: if the request fail, revert to the inital (empty) value.\n\nAfter that you can use the hooks/hocs provided by the library:\n\n### useSettings\n\n```javascript\nfunction AddressInput({ ...props }) {\n  const {\n    values: [gmapsKey],\n    isLoading,\n  } = useSettings(['settings.GOOGLE_MAPS_KEY']);\n\n  const gMapsStaus = useScript(gmapsKey ? scriptUrl(gmapsKey) : '');\n\n  if (isLoading) return null;\n\n  return \u003cGeoInput {...props} /\u003e;\n}\n```\n\n### withSettings\n\n```javascript\nfunction AddressInput({ gmapsKey, allowedCountries, ...props }) {\n  const country = allowedCountries?.split(',') || 'us';\n  const gMapsStaus = useScript(gmapsKey ? scriptUrl(gmapsKey) : '');\n\n  return \u003cGeoInput country={country} {...props} /\u003e;\n}\n\nconst options = {\n  settingsMap: {\n    gmapsKey: 'settings.GOOGLE_MAPS_KEY',\n    allowedCountries: 'settings.ALLOWED_COUNTRIES',\n  },\n  loadingComponent: Loading,\n};\n\nexport default withSettings(AddressInput, options);\n```\n\n### withFeatureFlag\n\n```javascript\nfunction ComponentV1() {\n  return \u003cspan\u003eV1\u003c/span\u003e;\n}\n\nfunction ComponentV2() {\n  return \u003cspan\u003eV2\u003c/span\u003e;\n}\n\nexport default withFeatureFlag(ComponentV2, {\n  flags: ['flags.ENABLE_COMPONENT_V1'],\n  fallbackComponent: ComponentV1,\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsmart%2Freact-frontend-settings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floadsmart%2Freact-frontend-settings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsmart%2Freact-frontend-settings/lists"}