{"id":27719394,"url":"https://github.com/tyrealhu/react-tapable","last_synced_at":"2025-06-14T04:06:24.073Z","repository":{"id":47304679,"uuid":"513938791","full_name":"TyrealHu/react-tapable","owner":"TyrealHu","description":"A variety of react subscription and distribution module","archived":false,"fork":false,"pushed_at":"2023-01-31T14:19:04.000Z","size":734,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-28T14:44:36.964Z","etag":null,"topics":["eventbus","events","hook","hooks","hooks-api","javascript","react","react-components","react-native","reactjs","tapable","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TyrealHu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-14T14:44:43.000Z","updated_at":"2023-03-27T02:11:00.000Z","dependencies_parsed_at":"2023-02-16T19:55:20.615Z","dependency_job_id":null,"html_url":"https://github.com/TyrealHu/react-tapable","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/TyrealHu/react-tapable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TyrealHu%2Freact-tapable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TyrealHu%2Freact-tapable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TyrealHu%2Freact-tapable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TyrealHu%2Freact-tapable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TyrealHu","download_url":"https://codeload.github.com/TyrealHu/react-tapable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TyrealHu%2Freact-tapable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259756872,"owners_count":22906678,"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":["eventbus","events","hook","hooks","hooks-api","javascript","react","react-components","react-native","reactjs","tapable","typescript"],"created_at":"2025-04-27T07:44:54.237Z","updated_at":"2025-06-14T04:06:24.035Z","avatar_url":"https://github.com/TyrealHu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-tapable [![npm version](https://img.shields.io/npm/v/react-tapable.svg?style=flat)](https://www.npmjs.com/package/react-tapable)[![Node.js CI](https://github.com/TyrealHu/react-tapable/actions/workflows/nodejs.yml/badge.svg?branch=main)](https://github.com/TyrealHu/react-tapable/actions/workflows/nodejs.yml)[![Coverage Status](https://codecov.io/gh/TyrealHu/react-tapable/branch/master/graph/badge.svg)](https://codecov.io/gh/TyrealHu/react-tapable)\n\nModule of React subscription and Distribution based on [tapable](https://github.com/webpack/tapable)\n\nWe have added two specific hooks to solve different situations, as detailed in [here](./doc/HOOKS.CN.md)\n\n## Quick Start\n\nYou can use this module in the following ways\n\n```typescript\nimport createTapableController, {SyncHook} from 'react-tapable'\n\nconst {\n    HooksNameMap,\n    tapHook,\n    call,\n    callAsync,\n    promise,\n    useTapable,\n    removeTapHook\n} = createTapableController\u003c{ testOne: string; testTwo: string }\u003e(\n    'Test',\n    {\n        testOne: new SyncHook([]),\n        testTwo: new SyncHook([])\n    }\n)\n```\n\n### React Hooks + useTapable\n\nYou can subscribe by directly using `useTapable` in the React Functional Component .\n\nYou can use `state` in `fn of useTapable`, and the registered function will automatically uninstall and re-listen according to the changes in the incoming `state`, without worrying about memory leaks.\n\n```tsx\n// import this function from the file where you called createTapableController\nimport {useTapable, HooksNameMap} from './tapable'\nimport * as React from 'react'\nimport {useState} from 'react'\n\nconst Component = () =\u003e {\n    const [count, setCount] = useState\u003cnumber\u003e(1)\n    useTapable(\n        {\n            hook: HooksNameMap.XXX,\n            mode: 'tap'\n        },\n        () =\u003e {\n            console.log(count)\n        },\n        [count]\n    )\n\n    return (\u003cdiv\u003eHello React Tapable\u003c/div\u003e)\n}\n```\n\n### React Component + tapHook + removeTapHook\n\nYou can subscribe by directly using `tapHook` in the React Component.\n\nYou can use `state` in `fn of tapHook` to registering function , and uninstall the function by `removeTapHook`.\n\n```tsx\n// import this function from the file where you called createTapableController\nimport {tapHook, removeTapHook, HooksNameMap} from './tapable'\nimport * as React from 'react'\n\nexport class Component extends React.Component {\n    constructor(props) {\n        super(props);\n\n        this.state = {\n            count: 1\n        }\n        \n        this.fn = () =\u003e {\n            console.log(this.state.count)\n        }\n        \n        tapHook({\n            hook: HooksNameMap.XXX,\n            mode: 'tap'\n        }, this.fn)\n    }\n    \n    componentWillUnMount() {\n        removeTapHook(HooksNameMap.XXX, 'tap', this.fn)\n    }\n}\n```\n\n## Method introduction\n\n### `HooksNameMap`\n\nThis map stores the names of all the hooks you have registered, and it can be used when you register the event\n```tsx\ncreateTapableController\u003c{ testOne: string; testTwo: string }\u003e(\n    'Test',\n    {\n        testOne: new SyncHook([]),\n        testTwo: new SyncHook([])\n    }\n)\n```\n\nFor example, in the case of the above, it will be `{testOne: 'testOne', testTwo: 'testTwo'}`\n\n### `call | callAsync | promise`\n\nThese three methods are used to trigger listening events.\n\n### `tapHook | removeTapHook`\n\nThese two methods are used to register events and uninstall events in React.Component\n\n### `useTapable`\n\nThis method is used to register events in react hooks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyrealhu%2Freact-tapable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyrealhu%2Freact-tapable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyrealhu%2Freact-tapable/lists"}