{"id":15319282,"url":"https://github.com/marcbouchenoire/use-merge-state","last_synced_at":"2025-10-13T20:34:00.514Z","repository":{"id":40251809,"uuid":"324740187","full_name":"marcbouchenoire/use-merge-state","owner":"marcbouchenoire","description":"🗜️ A useState variant hook that merges updates from arrays, plain objects, maps or sets.","archived":false,"fork":false,"pushed_at":"2025-02-24T13:30:05.000Z","size":1227,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-05T16:52:21.154Z","etag":null,"topics":["hook","merge","react","rest","spread","state"],"latest_commit_sha":null,"homepage":"https://npm.im/use-merge-state","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/marcbouchenoire.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,"zenodo":null}},"created_at":"2020-12-27T10:48:04.000Z","updated_at":"2025-02-24T13:30:11.000Z","dependencies_parsed_at":"2025-02-26T16:46:48.982Z","dependency_job_id":null,"html_url":"https://github.com/marcbouchenoire/use-merge-state","commit_stats":null,"previous_names":["bouchenoiremarc/use-merge-state"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/marcbouchenoire/use-merge-state","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbouchenoire%2Fuse-merge-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbouchenoire%2Fuse-merge-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbouchenoire%2Fuse-merge-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbouchenoire%2Fuse-merge-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcbouchenoire","download_url":"https://codeload.github.com/marcbouchenoire/use-merge-state/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbouchenoire%2Fuse-merge-state/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279016923,"owners_count":26085908,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hook","merge","react","rest","spread","state"],"created_at":"2024-10-01T09:04:21.494Z","updated_at":"2025-10-13T20:34:00.496Z","avatar_url":"https://github.com/marcbouchenoire.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-merge-state\n\n🗜️ A `useState` variant hook that merges updates from arrays, plain objects, maps or sets.\n\n[![build](https://img.shields.io/github/actions/workflow/status/marcbouchenoire/use-merge-state/.github/workflows/ci.yml)](https://github.com/marcbouchenoire/use-merge-state/actions/workflows/ci.yml)\n[![npm](https://img.shields.io/npm/v/use-merge-state?color=%230cf)](https://www.npmjs.com/package/use-merge-state)\n[![size](https://img.shields.io/bundlephobia/minzip/use-merge-state?label=size\u0026color=%2385f)](https://bundlephobia.com/package/use-merge-state)\n[![coverage](https://img.shields.io/codecov/c/github/marcbouchenoire/use-merge-state?color=%23e4b)](https://codecov.io/gh/marcbouchenoire/use-merge-state)\n[![license](https://img.shields.io/github/license/marcbouchenoire/use-merge-state?color=%23f81)](https://github.com/marcbouchenoire/use-merge-state/blob/main/LICENSE)\n\n- 📚 **Simple**: A drop-in `useState` replacement\n- 🗜️ **Tiny**: Just around **600 bytes** on modern platforms\n- 🧪 **Reliable**: Fully tested with [100% code coverage](https://codecov.io/gh/marcbouchenoire/use-merge-state)\n- 📦 **Typed**: Written in [TypeScript](https://www.typescriptlang.org/) and includes definitions out-of-the-box\n- 💨 **Zero dependencies**\n\n## Installation\n\n```bash\nnpm install use-merge-state\n```\n\n## Usage\n\nImport `useMergeState`.\n\n```typescript\nimport { useMergeState } from \"use-merge-state\"\n```\n\nUse it as a drop-in `useState` replacement.\n\n```typescript\nconst [state, setState] = useMergeState([1, 2])\n\n// state: [1, 2]\n```\n\nSetting arrays, plain objects, maps or sets will merge them with the current state instead of overriding it. Other types will be overridden similarly to `useState`.\n\n```typescript\nsetState([3, 4])\n\n// state: [1, 2, 3, 4]\n```\n\nReturning a functional update will run as expected and its result will then be merged with the current state.\n\n```typescript\nsetState((previousState) =\u003e\n  previousState.map((previousNumber) =\u003e previousNumber * 2)\n)\n\n// state: [1, 2, 3, 4, 2, 4, 6, 8]\n```\n\n## Options\n\nA secondary `options` argument can be set either on instances, updates or both to tweak the behavior of `useMergeState`.\n\nSetting `options` on a `useMergeState` instance will set options for all `setState` updates of this instance.\n\n```typescript\nconst [state, setState] = useMergeState([1, 2], {\n  merge: false\n})\n```\n\nSetting `options` on a `setState` update will override any previously set options for this specific update.\n\n```typescript\nsetState([3, 4], {\n  merge: true\n})\n```\n\n#### `merge`\n\n```typescript\nmerge?: boolean = true\n```\n\nSetting `merge` to `false` will disable merging—essentially converting `useMergeState` back into `useState`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcbouchenoire%2Fuse-merge-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcbouchenoire%2Fuse-merge-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcbouchenoire%2Fuse-merge-state/lists"}