{"id":19451190,"url":"https://github.com/thekashey/react-shallow-context","last_synced_at":"2025-09-23T16:30:55.576Z","repository":{"id":57344511,"uuid":"151498600","full_name":"theKashey/react-shallow-context","owner":"theKashey","description":"☘️A speed optimization for a Context API","archived":false,"fork":false,"pushed_at":"2019-05-04T22:33:27.000Z","size":151,"stargazers_count":117,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T03:50:19.675Z","etag":null,"topics":["context-api","purecomponent","react","shallow-equal"],"latest_commit_sha":null,"homepage":"","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/theKashey.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-04T00:28:34.000Z","updated_at":"2024-05-19T05:51:08.000Z","dependencies_parsed_at":"2022-09-11T09:00:57.407Z","dependency_job_id":null,"html_url":"https://github.com/theKashey/react-shallow-context","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/theKashey%2Freact-shallow-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theKashey%2Freact-shallow-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theKashey%2Freact-shallow-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theKashey%2Freact-shallow-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theKashey","download_url":"https://codeload.github.com/theKashey/react-shallow-context/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233984813,"owners_count":18761341,"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":["context-api","purecomponent","react","shallow-equal"],"created_at":"2024-11-10T16:40:40.500Z","updated_at":"2025-09-23T16:30:50.268Z","avatar_url":"https://github.com/theKashey.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eReact Shallow Context\u003c/h1\u003e\n  \u003cbr/\u003e\n  Pure shallow equal for update propagation in 300b.\n  \u003cbr/\u003e\n    \n  \u003ca href=\"https://www.npmjs.com/package/react-shallow-context\"\u003e\n   \u003cimg src=\"https://img.shields.io/npm/v/react-shallow-context.svg?style=flat-square\" /\u003e\n  \u003c/a\u003e\n  \n  \u003ca href=\"https://codecov.io/github/thekashey/react-shallow-context\"\u003e\n   \u003cimg src=\"https://img.shields.io/codecov/c/github/thekashey/react-shallow-context.svg?style=flat-square)\" /\u003e\n  \u003c/a\u003e\n  \n  \u003ca href=\"https://travis-ci.org/theKashey/react-shallow-context\"\u003e\n   \u003cimg src=\"https://travis-ci.org/theKashey/react-shallow-context.svg?branch=master\" /\u003e\n  \u003c/a\u003e\n\n  \u003cbr/\u003e  \n\u003c/div\u003e  \n\n# Goal\nThis package optimizes React.Context API by implementing `calculateChangedBits`, which works the same way as\n`shouldComponentUpdate` or `PureComponent` - it optimizes the way React reacts to context updates.\n\n# The problem\nIt is common to store an object inside of the context `Provider`:\n```js\n\u003cProvider value={{key1: 1, key2: 2}} /\u003e\n```\nHowever, that produces a new `value` every time, causing all `Consumers` to update. React then needs to traverse\nthe entire tree to find those `Consumer` components.\nThis package provides a way to handle when the value changes, and suppress unnecessary updates.\n\n# API\n\n## createPureContext(defaultValue)\nCreates \"pure\" context, the same way that \"PureComponent\" is \"pure.\" This is equivalent to `React.createContext(xx, pureContextCompare)`\n```js\n👎 import {createContext} from 'react';\nconst context = createContext();\n\n👍 import {createPureContext} from 'react-shallow-context';\nconst context = createPureContext();\n```\n\n## pureContextCompare\nShallow compares the old and next context value. It supresses the update if they are the same.\n```js\nimport {pureContextCompare} from 'react-shallow-context';\nconst context = React.createContext({}, pureContextCompare);\n\n// equal to\nconst context = createPureContext({});\n``` \n\n## updateIgnoring(keys)\nThe same as `pureContextCompare`, but it ignores selected keys. This is useful when the context contains some `callback` function that could always be different, \nbut only plays a role when another value is changed. \n```js\nimport {updateIgnoring} from 'react-shallow-context';\nconst context = React.createContext({importantValue, notImportantValue}, updateIgnoring(['notImportantValue']));\n```\n\n## updateOnlyFor(keys)\nThe inverse of `updateIgnoring`.  Will only trigger an update when the given `keys` change.\n```js\nimport {updateOnlyFor} from 'react-shallow-context';\nconst context = React.createContext({importantValue, notImportantValue}, updateOnlyFor(['importantValue']));\n```\n\n# Licence\n MIT\n \n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekashey%2Freact-shallow-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthekashey%2Freact-shallow-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekashey%2Freact-shallow-context/lists"}