{"id":23099179,"url":"https://github.com/guptasiddhant/react-trigger","last_synced_at":"2025-04-03T20:23:20.915Z","repository":{"id":47476315,"uuid":"246925209","full_name":"GuptaSiddhant/react-trigger","owner":"GuptaSiddhant","description":"Publish and listen to changes of Tiggers. Implementation of RxJs Subject. `npm i @guptasiddhant/react-trigger`","archived":false,"fork":false,"pushed_at":"2022-07-20T22:38:05.000Z","size":27,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T19:33:44.527Z","etag":null,"topics":["hooks","react","subscriber","trigger"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@guptasiddhant/react-trigger","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/GuptaSiddhant.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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":"2020-03-12T20:29:59.000Z","updated_at":"2023-03-08T22:10:40.000Z","dependencies_parsed_at":"2022-08-22T07:11:21.301Z","dependency_job_id":null,"html_url":"https://github.com/GuptaSiddhant/react-trigger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuptaSiddhant%2Freact-trigger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuptaSiddhant%2Freact-trigger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuptaSiddhant%2Freact-trigger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuptaSiddhant%2Freact-trigger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GuptaSiddhant","download_url":"https://codeload.github.com/GuptaSiddhant/react-trigger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247071713,"owners_count":20878743,"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":["hooks","react","subscriber","trigger"],"created_at":"2024-12-16T23:18:30.484Z","updated_at":"2025-04-03T20:23:20.889Z","avatar_url":"https://github.com/GuptaSiddhant.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Trigger\n\nPublish and listen to changes of Triggers. Implementation of RxJs Subject.\n\nRequires: React ^16.8 for hooks and RxJS.\n\n## Trigger\n\nTrigger instances can publish information and subscribe/listen to it anywhere else in the program.\n\n_In TypeScript, Pass a PayloadType to let the Trigger know what to expect while observing._\n\n### methods\n\n- **publish**: Publish (set) new payload\n- **subscribe**: Subscribe and listen to changes and execute a function.\n\n### example\n\n    import { Trigger } from \"@guptasiddhant/trigger\";\n\n    // TypeScript\n    type PayloadType = string;\n    const myTrigger = new Trigger\u003cPayloadType\u003e();\n\n    // JavaScript\n    const myTrigger = new Trigger();\n\n    // somewhere in code\n    myTrigger.publish(\"text\");\n\n    // somewhere else in code\n    myTrigger.useSubscribe((payload) =\u003e console.log(payload));\n    ==or==\n    useEffect(()=\u003e{\n        const sub = myTrigger.subscribe((payload) =\u003e console.log(payload))\n        return () =\u003e sub.unsubscribe();\n    }\n\n## useTrigger\n\nHook to listen to changes of Triggers (multiple)\n\n### params\n\n- **execute**: Function to run on Trigger\n- **deps**: Array of Triggers to listen to.\n\n### example\n\n    useTrigger((payload) =\u003e console.log(payload), [Trigger])\n\n    === or ===\n\n    useTrigger((payload) =\u003e console.log(payload), [Trigger1, Trigger2])\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguptasiddhant%2Freact-trigger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguptasiddhant%2Freact-trigger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguptasiddhant%2Freact-trigger/lists"}