{"id":26601940,"url":"https://github.com/patrickmarabeas/react-stateful-hoc","last_synced_at":"2026-04-19T06:33:07.486Z","repository":{"id":57345317,"uuid":"92230880","full_name":"patrickmarabeas/react-stateful-hoc","owner":"patrickmarabeas","description":"Higher Order Component for demoing stateless functional React components","archived":false,"fork":false,"pushed_at":"2017-06-14T07:21:39.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-01T11:08:36.004Z","etag":null,"topics":["reactjs","reactjs-components","reactjs-demo"],"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/patrickmarabeas.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":"2017-05-23T23:52:01.000Z","updated_at":"2018-01-26T12:30:54.000Z","dependencies_parsed_at":"2022-09-16T02:50:20.512Z","dependency_job_id":null,"html_url":"https://github.com/patrickmarabeas/react-stateful-hoc","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/patrickmarabeas/react-stateful-hoc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmarabeas%2Freact-stateful-hoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmarabeas%2Freact-stateful-hoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmarabeas%2Freact-stateful-hoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmarabeas%2Freact-stateful-hoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickmarabeas","download_url":"https://codeload.github.com/patrickmarabeas/react-stateful-hoc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmarabeas%2Freact-stateful-hoc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262950349,"owners_count":23389644,"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":["reactjs","reactjs-components","reactjs-demo"],"created_at":"2025-03-23T18:46:55.419Z","updated_at":"2026-04-19T06:33:07.381Z","avatar_url":"https://github.com/patrickmarabeas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-stateful-hoc\n\nHigher Order Component for demoing stateless functional React components\n\n## Demo Sandbox\n\n[https://codesandbox.io/s/Mj5MMXG4R](https://codesandbox.io/s/Mj5MMXG4R)\n\n## Usage\n\n\u003e npm i -D react-stateful-hoc\n\n```\n/** App */\n\nimport React from 'react';\nimport { render } from 'react-dom';\nimport StatefulHOC from 'react-stateful-hoc';\nimport { Clicker, onClickHandler, onClickHandlerAlternate } from 'Components/Clicker';\n\nconst ClickerMock = StatefulHOC(Clicker);\n\nconst ClickerDemo = ClickerMock({\n  onClick(prop) {\n    this.setState({ value: onClickHandler(this.value, prop) });\n  },\n});\n\n// *** or ***\n\nconst ClickerDemo2 = ClickerMock({\n  value: 0,\n  onClick(prop) {\n    this.setState((state, props) =\u003e ({\n      value: onClickHandler(state.value, prop),\n    }));\n  },\n});\n\n// *** or ***\n\nconst ClickerDemo3 = ClickerMock({\n  onClick(value) {\n    this.setState(onClickHandlerAlternate(this, value));\n  },\n});\n\nconst App = () =\u003e\n  \u003cdiv\u003e\n    \u003cClickerDemo /\u003e\n    \u003cClickerDemo2 /\u003e\n    \u003cClickerDemo3 /\u003e\n  \u003c/div\u003e;\nrender(\u003cApp /\u003e, document.getElementById('root'));\n\n```\n\n```\n/** components/Clicker */\n\nimport React from 'react';\nimport propTypes from 'prop-types';\n\nconst Clicker = (props) =\u003e {\n  const { value } = props; // event handlers will need to reference props directly to maintain scope\n  return \u003cdiv onClick={() =\u003e props.onClick(1)}\u003eCLICK ME: {value}\u003c/div\u003e;\n};\n\nClicker.propTypes = {\n  value: propTypes.number.isRequired,\n  onClick: propTypes.func.isRequired\n};\n\nClicker.defaultProps = {\n  value: 0\n};\n\nfunction onClickHandler(state, payload) {\n  return state += payload;\n}\n\n// *** or ***\n\nfunction onClickHandlerAlternate(state, props) {\n  return {\n    value: state.value + props\n  }\n}\n\nexport { Clicker, onClickHandler, onClickHandlerAlternate };\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickmarabeas%2Freact-stateful-hoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickmarabeas%2Freact-stateful-hoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickmarabeas%2Freact-stateful-hoc/lists"}