{"id":13647487,"url":"https://github.com/captivationsoftware/react-global","last_synced_at":"2025-04-13T05:39:51.070Z","repository":{"id":27857607,"uuid":"31348244","full_name":"captivationsoftware/react-global","owner":"captivationsoftware","description":"\u003cGlobal /\u003e component for isomorphic React apps","archived":false,"fork":false,"pushed_at":"2017-08-07T00:07:56.000Z","size":132,"stargazers_count":22,"open_issues_count":4,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T23:47:23.407Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/captivationsoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-26T03:09:47.000Z","updated_at":"2021-09-05T13:20:02.000Z","dependencies_parsed_at":"2022-09-03T13:52:07.797Z","dependency_job_id":null,"html_url":"https://github.com/captivationsoftware/react-global","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captivationsoftware%2Freact-global","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captivationsoftware%2Freact-global/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captivationsoftware%2Freact-global/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captivationsoftware%2Freact-global/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/captivationsoftware","download_url":"https://codeload.github.com/captivationsoftware/react-global/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248670507,"owners_count":21142897,"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":"2024-08-02T01:03:35.786Z","updated_at":"2025-04-13T05:39:50.685Z","avatar_url":"https://github.com/captivationsoftware.png","language":"JavaScript","readme":"react-global\n============\n\nA simple React component for exposing global properties on your page. This library is particularly useful for isomorphic apps, where a set of values must be shared between the server and client (e.g. passing initialization variables to third-party libraries).\n\n## Installation\n```sh\nnpm install react-global\n```\n## Code Examples\n\n### Setting Global Values\n\n```js\nvar Global = require('react-global');\n\n\u003cGlobal values={{\n  FOO: this.props.foo,\n  BAR: this.props.bar\n}} /\u003e\n\n```\n\n### Getting Global Values\n```js\nGlobal.get('FOO')\n```\n\nNote: every Global variable that you declare will actually be available on the window object as a true browser global.\n```js\n  Global.get('FOO') === window.FOO === window['FOO'] === FOO\n    \n```\n\n## Use Case\nThis component is meant to ease the case where your isomorphic app's server has some configuration variable's that need to be shared with the browser that will never change over the course of the user's interaction with your app. Below you will find a reusable pattern for accomplishing this task cleanly and concisely using react-global.\n\nserver.js\n```js\nvar React = require('React'),\n  App = require('./views/App.jsx');\n\napp.get('/', function(req, res) {\n  var markup = React.renderToString(\u003cApp clientApiKey={config.client.api.key} /\u003e);\n  res.send('\u003c!DOCTYPE html\u003e' + markup);\n});\n\n```\n\nApp.jsx\n```js\nvar React = require('react'),\n  Global = require('react-global');\n\nvar App = React.createClass({\n\n  componentDidMount: function() {\n    ClientLib.init(this.props.clientApiKey);    \n  },\n\n  render: function() {\n    ...\n      \u003cGlobal values={{\n        CLIENT_API_KEY: this.props.clientApiKey\n      }} /\u003e\n    ...\n  }\n});\n\n// Mount the app if in the browser\nif (window \u0026\u0026 document) {\n  React.render(\u003cApp clientApiKey={Global.get('CLIENT_API_KEY')} /\u003e\n}\n\n```\n\nA simple but useful pattern!\n\n## Contributors\n\nImplementation by Captivation Software (@teamcaptivation), overall design by Adam Nalisnick (@theadam4257)\n\nBy all means, if you see room for improvement, let us know!\n\n## License\n\nMIT License\n\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptivationsoftware%2Freact-global","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaptivationsoftware%2Freact-global","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptivationsoftware%2Freact-global/lists"}