{"id":23635352,"url":"https://github.com/filefoxper/react-class-hookable","last_synced_at":"2026-04-16T19:48:08.633Z","repository":{"id":128607782,"uuid":"302687096","full_name":"filefoxper/react-class-hookable","owner":"filefoxper","description":"for using react hooks in class component","archived":false,"fork":false,"pushed_at":"2020-11-08T05:00:06.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-19T04:09:30.243Z","etag":null,"topics":["class-component","class-component-hooks","front-end","hooks","react","react-hoc","react-hooks","typescript"],"latest_commit_sha":null,"homepage":"","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/filefoxper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-10-09T15:50:50.000Z","updated_at":"2020-11-08T05:00:08.000Z","dependencies_parsed_at":"2023-06-07T21:45:47.017Z","dependency_job_id":null,"html_url":"https://github.com/filefoxper/react-class-hookable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/filefoxper/react-class-hookable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Freact-class-hookable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Freact-class-hookable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Freact-class-hookable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Freact-class-hookable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/filefoxper","download_url":"https://codeload.github.com/filefoxper/react-class-hookable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filefoxper%2Freact-class-hookable/sbom","scorecard":{"id":399478,"data":{"date":"2025-08-11","repo":{"name":"github.com/filefoxper/react-class-hookable","commit":"cd7f54c4db9557dc105954cdce7267ed782d27a1"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/14 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-18T19:47:07.188Z","repository_id":128607782,"created_at":"2025-08-18T19:47:07.188Z","updated_at":"2025-08-18T19:47:07.188Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31902123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"ssl_error","status_checked_at":"2026-04-16T18:21:47.142Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["class-component","class-component-hooks","front-end","hooks","react","react-hoc","react-hooks","typescript"],"created_at":"2024-12-28T05:34:07.214Z","updated_at":"2026-04-16T19:48:08.625Z","avatar_url":"https://github.com/filefoxper.png","language":"TypeScript","readme":"[![npm][npm-image]][npm-url]\n[![standard][standard-image]][standard-url]\n\n[npm-image]: https://img.shields.io/npm/v/react-class-hookable.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/react-class-hookable\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square\n[standard-url]: http://npm.im/standard\n\n# problem\n\nMake react class component hook-able. Sometimes, transforming class component to a functional component is not a easy work,\nbut, if not, we can not use react-hooks (or custom hooks) in the old class component. So, \nhow to use hooks in class component just like in functional component? \n\n# resolver\n\nThe tool 'react-class-hookable' contains a simple high order component. You can use it to resolve the problem.\nAnd it is simple enough, you can view the source code for seconds.  \n\n# install\n```\nnpm install --save react-class-hookable\n```\n\n# usage\n\n[view example](https://github.com/filefoxper/react-class-hookable/tree/master/example/basic)\n\n```typescript jsx\nimport React,{Component,useState,useCallback} from 'react';\nimport hookable from 'react-class-hookable';\n\nclass ComplexComponent extends Component{\n    \n    state = {...};\n    \n    componentDidMount(){\n        // doing ......\n    }\n    \n    componentDidUpdate(){\n        // doing ......\n    }\n    \n    handleEvent = ()=\u003e{\n        this.setState({...});\n    };\n    \n    complexRender=()=\u003e{\n        const [count,setCount] = useState(0);\n                \n        const handleAddCount = useCallback(()=\u003e{\n            setCount((c)=\u003ec+1);\n        },[]);\n        return (\n            \u003cbutton onClick={handleAddCount}\u003efunction render:{count}\u003c/button\u003e\n        );\n    };\n    \n    render(){\n        const state = this.state;\n        const props = this.props;\n        //use hook just like how using in functional component\n        const [count,setCount] = useState(0);\n        \n        const handleAddCount = useCallback(()=\u003e{\n            setCount((c)=\u003ec+1);\n        },[]);\n        \n        return (\n            \u003cdiv\u003e\n              \u003cbutton onClick={handleAddCount}\u003ehook count: {count}\u003c/button\u003e\n              \u003cbutton onClick={this.handleEvent}\u003erun event\u003c/button\u003e\n              {this.complexRender()}\n            \u003c/div\u003e\n        );\n    }\n    \n}\n\nexport default hookable(ComplexComponent);\n```\nIf you are using decorator, it can be more easy.\n```typescript jsx\nimport React,{Component,useState,useCallback} from 'react';\nimport {withHookable} from 'react-class-hookable';\n\n@withHookable()\nexport default class ComplexComponent extends Component{\n    //......\n}\n```\nIt is simple, you can use any hooks which is also using in your functional component now.\n\n# api\n\n#### hookable\n```typescript jsx\nexport default function hookable\u003cP = {}, S = ComponentState\u003e(\n    SourceClass: ComponentClass\u003cP, S\u003e,\n    hasOwnRenderProp?:boolean\n): ComponentClass\u003cP, S\u003e\n```\n`hookable` has an optional param `hasOwnRenderProp`, if you want the `render` function in component own props always invokes,\nyou can set it a `true` value. If not `hookable` will auto select the `render` function. \n\n(\n`hookable` auto select will find out a `render` function in the prototype of your component class first,\nif exist, it will use it, if not it will use the own property `render` function or throw an unavailable exception\n)\n\n#### hookable.currying\n```typescript jsx\ntype HookableCurryingCallback\u003cP = {}, S = ComponentState\u003e = (SourceClass: ComponentClass\u003cP,S\u003e) =\u003e ComponentClass\u003cP,S\u003e;\n\nfunction currying(hasOwnRenderProp?: boolean):HookableCurryingCallback\n```\nThis is the currying function for `hookable`, you can use `hasOwnRenderProp config` to create a factory\n`hookable` function.\n###### ~~hookDecorator~~ (deprecated)\n\n`hookDecorator` is deprecated, but still works, we recommend you to use `withHookable`.\n\n#### withHookable\n```typescript jsx\nexport function withHookable(hasOwnRenderProp?: boolean):Function\n```\n\nusage\n\n```typescript jsx\nimport React,{Component} from 'react';\nimport {withHookable} from 'react-class-hookable';\n\n@withHookable\nclass Comp extends Component{\n    \n}\n```\nIf you are using typescript, you may find `incompatible warnings`, so here is a new decorator function for you.\n\n# before using\n\nYou should know it is not recommended to use hooks in the old class component. \nThis usage is only temporary, so you'd better add an annotation like `//todo trans to functional component in future`.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilefoxper%2Freact-class-hookable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilefoxper%2Freact-class-hookable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilefoxper%2Freact-class-hookable/lists"}