{"id":13452056,"url":"https://github.com/CanopyTax/use-once","last_synced_at":"2025-03-23T19:33:30.552Z","repository":{"id":57388252,"uuid":"155260809","full_name":"CanopyTax/use-once","owner":"CanopyTax","description":"A helper for running react effects only once","archived":false,"fork":false,"pushed_at":"2018-10-29T18:46:03.000Z","size":29,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-24T22:20:27.535Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/CanopyTax.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":"2018-10-29T18:25:57.000Z","updated_at":"2019-05-05T12:27:15.000Z","dependencies_parsed_at":"2022-09-09T18:11:58.922Z","dependency_job_id":null,"html_url":"https://github.com/CanopyTax/use-once","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CanopyTax%2Fuse-once","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CanopyTax%2Fuse-once/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CanopyTax%2Fuse-once/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CanopyTax%2Fuse-once/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CanopyTax","download_url":"https://codeload.github.com/CanopyTax/use-once/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244250363,"owners_count":20423147,"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":[],"created_at":"2024-07-31T07:01:11.428Z","updated_at":"2025-03-23T19:33:30.170Z","avatar_url":"https://github.com/CanopyTax.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# use-once\nA helper for running react effects only once.\n\n## Motivation\nFor beginners, it isn't clear that `useEffect(cbk, [])` [runs only once](https://reactjs.org/docs/hooks-reference.html#conditionally-firing-an-effect) and that `useEffect(cbk)` [runs every time](https://reactjs.org/docs/hooks-reference.html#useeffect).\nUsing this package avoids that confusion.\n\n## Installation\n```bash\nnpm install --save use-once\n\n# Or\n\nyarn add use-once\n```\n\n## Usage\n```js\nimport {useOnce} from 'use-once'\n\nfunction ReactComp(props) {\n  useOnce(() =\u003e {\n    console.log('This will only be run once for each instance of the component, instead of after every update.')\n\n    return () =\u003e {\n      console.log('Returning a function is optional. The returned function will be called when the component is unmounted.')\n    }\n  })\n\n  return null\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCanopyTax%2Fuse-once","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCanopyTax%2Fuse-once","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCanopyTax%2Fuse-once/lists"}