{"id":26109754,"url":"https://github.com/ryotasugawara/react-css-context","last_synced_at":"2025-04-12T21:25:05.809Z","repository":{"id":65482981,"uuid":"142538192","full_name":"RyotaSugawara/react-css-context","owner":"RyotaSugawara","description":"Isomorphic-loading CSS in our React Application.","archived":false,"fork":false,"pushed_at":"2019-07-11T06:18:50.000Z","size":330,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-26T15:42:14.247Z","etag":null,"topics":["css","isomorphic","javascript","react","typescript","universal-javascript","universal-react"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/RyotaSugawara.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":"2018-07-27T06:40:08.000Z","updated_at":"2019-09-21T02:26:42.000Z","dependencies_parsed_at":"2023-01-25T11:15:34.773Z","dependency_job_id":null,"html_url":"https://github.com/RyotaSugawara/react-css-context","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyotaSugawara%2Freact-css-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyotaSugawara%2Freact-css-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyotaSugawara%2Freact-css-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyotaSugawara%2Freact-css-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RyotaSugawara","download_url":"https://codeload.github.com/RyotaSugawara/react-css-context/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248633236,"owners_count":21136836,"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":["css","isomorphic","javascript","react","typescript","universal-javascript","universal-react"],"created_at":"2025-03-09T23:54:55.372Z","updated_at":"2025-04-12T21:25:05.779Z","avatar_url":"https://github.com/RyotaSugawara.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-css-context\n\nAsync Loading CSS file in our React Application.\nOf course we can use in Isomorphic Application!\n\n## Install\n\n```\n$ npm install react-css-context -S\n```\n\n## Usage\n\n### At Component where you want to load css.\n\n```tsx\nimport * as React from 'react';\nimport { CSSCollector } from 'react-css-context';\n\nexport class SomeComponent extends React.Component {\n  return (\n    \u003cCSSCollector hrefs={[\"absolute/url/of/css\"]}\u003e\n      \u003cdiv\u003edisplay after css loaded.\u003c/div\u003e\n    \u003c/CSSCollector\u003e\n  );\n}\n```\n\n**`href` must be absolute url**\n- NG: `/path/to/some.css`\n- OK: `https://ryotasugawara.github.io/absolute/url.css`\n\n### Server Side Rendering\n\n```tsx\nimport * as React from 'react';\nimport * as ReactDOMServer from 'react-dom/server';\nimport { CSSProvider, toTagString, toTagComponent } from 'react-css-context';\n\nconst cssMap = new Map();\nconst renderOutput = ReactDOMServer.renderToString(\n  \u003cCSSProvider cssMap={cssMap}\u003e\n    \u003cApp\u003e\n      \u003cSomeComponent /\u003e\n    \u003c/App\u003e\n  \u003c/CSSProvider\u003e\n);\n\n// use string\nconst htmlOutput = `\n\u003chtml\u003e\n  \u003chead\u003e\n    ${toTagString(cssMap)}\n  \u003c/head\u003e\n  ...\n\u003c/html\u003e\n`;\n\n// use component\nconst htmlOutput = renderToString(\n  \u003chtml\u003e\n    \u003chead\u003e\n      {toTagComponent(cssMap)}\n    \u003c/head\u003e\n    ...\n  \u003c/html\u003e\n);\n```\n\n### Client Side Rendering\n\n```tsx\nimport * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { CSSProvider, getCSSMap } from 'react-css-context';\n\n// get CSS-Map from browser head.\nconst cssMap = getCSSMap();\n\nReactDOM.render(\n  \u003cCSSProvider cssMap={cssMap}\u003e\n    \u003cApp\u003e\n      \u003cSomeComponent /\u003e\n    \u003c/App\u003e\n  \u003c/CSSProvider\u003e,\n  document.getElementById('main')\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryotasugawara%2Freact-css-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryotasugawara%2Freact-css-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryotasugawara%2Freact-css-context/lists"}