{"id":18850787,"url":"https://github.com/luqmanoop/react-mitt","last_synced_at":"2025-04-14T09:41:12.851Z","repository":{"id":97223272,"uuid":"270061913","full_name":"luqmanoop/react-mitt","owner":"luqmanoop","description":"React event emitter / pubsub 👉🏻👈🏽","archived":false,"fork":false,"pushed_at":"2020-06-07T14:17:34.000Z","size":996,"stargazers_count":30,"open_issues_count":2,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-06T22:33:01.715Z","etag":null,"topics":["eventemitter","events","mitt","pubsub","react","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-mitt","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/luqmanoop.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-06T18:03:34.000Z","updated_at":"2025-03-31T11:26:40.000Z","dependencies_parsed_at":"2023-03-22T10:18:06.412Z","dependency_job_id":null,"html_url":"https://github.com/luqmanoop/react-mitt","commit_stats":null,"previous_names":["luqmanoop/react-mitt"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luqmanoop%2Freact-mitt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luqmanoop%2Freact-mitt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luqmanoop%2Freact-mitt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luqmanoop%2Freact-mitt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luqmanoop","download_url":"https://codeload.github.com/luqmanoop/react-mitt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248855732,"owners_count":21172635,"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":["eventemitter","events","mitt","pubsub","react","typescript"],"created_at":"2024-11-08T03:31:39.044Z","updated_at":"2025-04-14T09:41:12.822Z","avatar_url":"https://github.com/luqmanoop.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-mitt\n\n\u003e React event emitter / pubsub\n\u003cdiv\u003e\n\u003cimg alt=\"react-mitt build status\" src=\"https://img.shields.io/travis/codeshifu/react-mitt.svg?logo=travis\"\u003e\n\t\u003cimg alt=\"react-mitt code coverage\" src=\"https://img.shields.io/coveralls/github/codeshifu/react-mitt.svg?style=popout\"\u003e\n\u003c/div\u003e\n\nA react wrapper for the awesome [mitt](https://github.com/developit/mitt) library\n\nLive demo https://codesandbox.io/s/react-mitt-demo-n11ii\n\n## Install\n\n```sh\n$ npm install react-mitt\n```\n\n## Usage\n\nWrap your app in the `MittProvider` component, providing descendants access to the `useMitt` hook for event pubsub\n\n```jsx\nimport { MittProvider } from \"react-mitt\"\n\nfunction App() {\n  return (\n    \u003cMittProvider\u003e\n      \u003cComponentA /\u003e\n      \u003cComponentB /\u003e\n    \u003c/MittProvider\u003e\n  )\n}\n```\n\n## Example\n\nOnce you wrap your app with the `MittProvider` as demonstrated [above](https://github.com/codeshifu/react-mitt#usage), event pubsub becomes a breeze with the `useMitt` hook\n\n```jsx\nimport { useMitt } from 'react-mitt'\n\nfunction ComponentA() {\n  const { emitter } = useMitt()\n\n  const handleClick = () =\u003e {\n    emitter.emit('foo', { data: 'ComponentA says foo!'})\n  }\n\n  return \u003cbutton onClick={handleClick}\u003eemit!\u003c/button\u003e\n}\n\nfunction ComponentB() {\n  const { emitter } = useMitt()\n\n  useEffect(() =\u003e {\n    // listen and respond to 'foo' events\n    emitter.on('foo', event =\u003e alert(event.data))\n  }, [])\n\n  return ...\n}\n\n```\n\n## Hook\n\nThe `useMitt` hook has the following signature\n\n```js\nconst { emitter } = useMitt()\n```\n\nFor usage of the **emitter** object, see **mitt** API [docs](https://github.com/developit/mitt#api)\n\n## License\n[MIT License](https://github.com/codeshifu/react-mitt/blob/master/license)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluqmanoop%2Freact-mitt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluqmanoop%2Freact-mitt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluqmanoop%2Freact-mitt/lists"}