{"id":13451755,"url":"https://github.com/reactions/component","last_synced_at":"2025-03-23T19:32:38.932Z","repository":{"id":29482043,"uuid":"121820036","full_name":"reactions/component","owner":"reactions","description":"Declarative version of React.Component","archived":false,"fork":false,"pushed_at":"2022-12-06T19:46:38.000Z","size":377,"stargazers_count":1061,"open_issues_count":21,"forks_count":37,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-04-15T12:47:44.392Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ui.reach.tech/component-component","language":"HTML","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/reactions.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-02-17T02:03:57.000Z","updated_at":"2024-03-11T03:13:32.000Z","dependencies_parsed_at":"2023-01-14T15:15:20.011Z","dependency_job_id":null,"html_url":"https://github.com/reactions/component","commit_stats":null,"previous_names":["ryanflorence/react-component-component"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactions%2Fcomponent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactions%2Fcomponent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactions%2Fcomponent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactions%2Fcomponent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reactions","download_url":"https://codeload.github.com/reactions/component/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213325084,"owners_count":15570231,"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-07-31T07:01:01.412Z","updated_at":"2024-07-31T07:04:06.254Z","avatar_url":"https://github.com/reactions.png","language":"HTML","readme":"# Reactions Component\n\nThis has moved to [Reach UI](https://ui.reach.tech/component-component), but this repo is here for the sake of history I guess.\n\n## What?\n\nDeclarative version of React.Component.\n\n## Why?\n\nBecause sometimes you want a lifecycle or some state but don't want to create a new component. Also, this stuff is composable as heck.\n\n## Installation\n\n```bash\nnpm install @reactions/component\n# or\nyarn add @reactions/component\n```\n\nAnd then import it:\n\n```js\n// using es modules\nimport Component from \"@reactions/component\";\n\n// common.js\nconst Component = require(\"@reactions/component\");\n\n// AMD\n// I've forgotten but it should work.\n```\n\nOr use script tags and globals.\n\n```html\n\u003cscript src=\"https://unpkg.com/@reactions/component\"\u003e\u003c/script\u003e\n```\n\nAnd then grab it off the global like so:\n\n```js\nconst Component = ReactionsComponent;\n```\n\n## How?\n\nLet's say you want some async data but don't want to make a whole new component just for the lifecycles to get it:\n\n```render-babel\n// import Component from '@reactions/component'\nconst Component = ReactComponentComponent;\n\nReactDOM.render(\n  \u003cdiv\u003e\n    \u003ch2\u003eLet's get some gists!\u003c/h2\u003e\n    \u003cComponent\n      initialState={{ gists: null }}\n      didMount={({ setState }) =\u003e {\n        fetch(\"https://api.github.com/gists\")\n          .then(res =\u003e res.json())\n          .then(gists =\u003e setState({ gists }));\n      }}\n    \u003e\n      {({ state }) =\u003e\n        state.gists ? (\n          \u003cul\u003e\n            {state.gists.map(gist =\u003e (\n              \u003cli key={gist.id}\u003e{gist.description}\u003c/li\u003e\n            ))}\n          \u003c/ul\u003e\n        ) : (\n          \u003cdiv\u003eLoading...\u003c/div\u003e\n        )\n      }\n    \u003c/Component\u003e\n  \u003c/div\u003e,\n  DOM_NODE\n);\n```\n\nOr maybe you need a little bit of state but an entire component\nseems a bit heavy:\n\n```render-babel\n// import Component from '@reactions/component'\nconst Component = ReactComponentComponent;\n\nReactDOM.render(\n  \u003cComponent initialState={{ count: 0 }}\u003e\n    {({ setState, state }) =\u003e (\n      \u003cdiv\u003e\n        \u003ch2\u003eEvery app needs a counter!\u003c/h2\u003e\n        \u003cbutton\n          onClick={() =\u003e\n            setState(state =\u003e ({ count: state.count - 1 }))\n          }\n        \u003e\n          -\n        \u003c/button\u003e\n        \u003cspan\u003e {state.count} \u003c/span\u003e\n        \u003cbutton\n          onClick={() =\u003e\n            setState(state =\u003e ({ count: state.count + 1 }))\n          }\n        \u003e\n          +\n        \u003c/button\u003e\n      \u003c/div\u003e\n    )}\n  \u003c/Component\u003e,\n  DOM_NODE\n);\n```\n\n## Props\n\nYou know all of these already:\n\n* `didMount({ state, setState, props, forceUpdate })`\n* `shouldUpdate({ state, props, nextProps, nextState })`\n* `didUpdate({ state, setState, props, forceUpdate, prevProps, prevState })`\n* `willUnmount({ state, props })`\n* `children({ state, setState, props, forceUpdate })`\n* `render({ state, setState, props, forceUpdate })`\n\n## Legal\n\nReleased under MIT license.\n\nCopyright \u0026copy; 2017-present Ryan Florence\n","funding_links":[],"categories":["HTML"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactions%2Fcomponent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactions%2Fcomponent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactions%2Fcomponent/lists"}