{"id":23186098,"url":"https://github.com/termosa/use-last-ref","last_synced_at":"2025-04-05T04:45:04.442Z","repository":{"id":183444586,"uuid":"669541611","full_name":"termosa/use-last-ref","owner":"termosa","description":"Constantly updating ref value from the argument","archived":false,"fork":false,"pushed_at":"2023-07-22T16:03:36.000Z","size":440,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T12:43:55.421Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/termosa.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,"governance":null}},"created_at":"2023-07-22T16:03:00.000Z","updated_at":"2023-07-22T16:03:42.000Z","dependencies_parsed_at":"2023-07-24T14:39:24.658Z","dependency_job_id":null,"html_url":"https://github.com/termosa/use-last-ref","commit_stats":null,"previous_names":["termosa/use-last-ref"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/termosa%2Fuse-last-ref","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/termosa%2Fuse-last-ref/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/termosa%2Fuse-last-ref/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/termosa%2Fuse-last-ref/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/termosa","download_url":"https://codeload.github.com/termosa/use-last-ref/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289400,"owners_count":20914464,"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-12-18T10:14:41.237Z","updated_at":"2025-04-05T04:45:04.420Z","avatar_url":"https://github.com/termosa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-last-ref\n\n\u003e Constantly updating ref value from the argument\n\n[![NPM](https://img.shields.io/npm/v/use-last-ref.svg)](https://www.npmjs.com/package/use-last-ref) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n## Install\n\n```bash\nnpm install --save use-last-ref\n```\n\n## Usage\n\n```tsx\nimport * as React from 'react'\nimport api from \"./api\"\n\nimport useLastRef from 'use-last-ref'\n// Or: import { useLastRef } from 'use-last-ref'\n\nconst ExampleInput = ({ value }: { value?: string }) =\u003e {\n  const valueRef = useLastRef(value)\n\n  const save = React.useCallback((newValue: string) =\u003e {\n    // Instead of adding `[value]` to `useCallback` dependency list\n    // and updating `save` function and `\u003cCustomSelect\u003e` component\n    // we use React reference feature to always access updated value\n\n    // Prevent submitting the save value\n    if (newValue !== valueRef.current) {\n      api.saveNewValue(newValue)\n    }\n  }, [])\n\n  return \u003cCustomSelect onSelect={save} /\u003e\n}\n```\n\n## License\n\nMIT © [termosa](https://github.com/termosa)\n\n---\n\nThis hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftermosa%2Fuse-last-ref","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftermosa%2Fuse-last-ref","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftermosa%2Fuse-last-ref/lists"}