{"id":22511554,"url":"https://github.com/codepunkt/should-not-update","last_synced_at":"2025-08-03T14:32:30.787Z","repository":{"id":57156720,"uuid":"78968615","full_name":"codepunkt/should-not-update","owner":"codepunkt","description":"Declarative shouldComponentUpdate wrapper","archived":false,"fork":false,"pushed_at":"2018-03-30T20:53:19.000Z","size":66,"stargazers_count":4,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-15T00:58:33.152Z","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/codepunkt.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":"2017-01-14T21:48:27.000Z","updated_at":"2019-06-09T00:30:34.000Z","dependencies_parsed_at":"2022-08-30T03:21:39.233Z","dependency_job_id":null,"html_url":"https://github.com/codepunkt/should-not-update","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepunkt%2Fshould-not-update","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepunkt%2Fshould-not-update/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepunkt%2Fshould-not-update/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepunkt%2Fshould-not-update/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codepunkt","download_url":"https://codeload.github.com/codepunkt/should-not-update/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228548560,"owners_count":17935226,"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-07T02:13:14.043Z","updated_at":"2024-12-07T02:13:14.618Z","avatar_url":"https://github.com/codepunkt.png","language":"JavaScript","readme":"# ShouldNotUpdate\n[![npm version](https://badge.fury.io/js/should-not-update.svg)](https://badge.fury.io/js/should-not-update) [![Build Status](https://travis-ci.org/codepunkt/should-not-update.svg?branch=master)](https://travis-ci.org/codepunkt/should-not-update) [![Coverage Status](https://coveralls.io/repos/github/codepunkt/should-not-update/badge.svg?branch=master)](https://coveralls.io/github/codepunkt/should-not-update?branch=master)\n\nSimple component utilizing the `shouldComponentUpdate` lifecycle hook. Wrap it around child components that you don't want to rerender on property changes.\n```javascript\nimport ShouldNotUpdate from 'should-not-update'\n\nconst MyComponent = ({ someProp }) =\u003e (\n  \u003cShouldNotUpdate\u003e\n    \u003cInnerComponent someProp={someProp}\u003e\n      This is not updating on property change\n    \u003c/InnerComponent\u003e\n  \u003c/ShouldNotUpdate\u003e\n)\n```\n### Rendered component\nBy default, `ShouldNotUpdate` will render as a `div` element, but that can be changed by setting the `component` prop, which accepts either a tag name string (such as 'div' or 'span')\n```javascript\n\u003cShouldNotUpdate component=\"ul\"\u003e\n```\nor a React component type (a class or a function), which should render their children to be useful.\n```javascript\nconst MyComponent = ({ children }) =\u003e (\n  \u003cdiv\u003e\n    {children}\n  \u003c/div\u003e\n)\n\n\u003cShouldNotUpdate component={MyComponent}\u003e\n```\n### Exceptions to the rule\nSometimes you want child components to re-render under certain conditions. You can add these conditions by setting the `exceptWhen` prop.\n```javascript\nconst MyComponent = ({ someProp }) =\u003e (\n  \u003cShouldNotUpdate exceptWhen={someProp === 42}\u003e\n    \u003cInnerComponent someProp={someProp}\u003e\n      This only updates on property change when someProp is 42\n    \u003c/InnerComponent\u003e\n  \u003c/ShouldNotUpdate\u003e\n)\n```\n\n### Other properties\nAll properties besides `children`, `component` and `exceptWhen` are directly passed to the rendered component.\n```javascript\nconst MyComponent = ({ someProp }) =\u003e (\n  \u003cShouldNotUpdate component=\"nav\" role=\"navigation\"\u003e\n    \u003cInnerComponent someProp={someProp}\u003e\n      This is not updating on property change\n    \u003c/InnerComponent\u003e\n  \u003c/ShouldNotUpdate\u003e\n)\n```\n### Use cases\nAmongst others, one possible use case is not re-rendering static children of a [react-motion](https://github.com/chenglou/react-motion) spring animation on every animation frame.\n```javascript\nimport { Link } from 'react-router'\nimport { Motion, spring } from 'react-motion'\n\nconst OffCanvas = ({ isVisible }) =\u003e (\n  \u003cMotion style={{ left: spring(isVisible ? 0 : -250) }}\u003e\n    {style =\u003e \u003cnav role=\"navigation\" style={style}\u003e\n      \u003cShouldNotUpdate component=\"ul\"\u003e\n        \u003cli\u003e\u003cLink to=\"/\"\u003eHome\u003c/Link\u003e\u003c/li\u003e\n      \u003c/ShouldNotUpdate\u003e\n    \u003c/nav\u003e}\n  \u003c/Motion\u003e\n);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodepunkt%2Fshould-not-update","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodepunkt%2Fshould-not-update","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodepunkt%2Fshould-not-update/lists"}