{"id":21195628,"url":"https://github.com/qiqiboy/memo-render","last_synced_at":"2026-01-19T15:01:55.182Z","repository":{"id":57294427,"uuid":"245738245","full_name":"qiqiboy/memo-render","owner":"qiqiboy","description":"A react-component for optimizing performance when it's parent re-renders.","archived":false,"fork":false,"pushed_at":"2024-09-26T22:17:16.000Z","size":21,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-30T13:48:40.210Z","etag":null,"topics":["react","react-component","react-memo","react-performace","react-render","shouldcomponentupdate"],"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/qiqiboy.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-08T02:20:34.000Z","updated_at":"2020-03-19T03:03:12.000Z","dependencies_parsed_at":"2024-11-20T19:33:38.046Z","dependency_job_id":"7439e647-cc92-45e1-92a4-943c246635e6","html_url":"https://github.com/qiqiboy/memo-render","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/qiqiboy/memo-render","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fmemo-render","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fmemo-render/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fmemo-render/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fmemo-render/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qiqiboy","download_url":"https://codeload.github.com/qiqiboy/memo-render/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fmemo-render/sbom","scorecard":{"id":753711,"data":{"date":"2025-08-11","repo":{"name":"github.com/qiqiboy/memo-render","commit":"97cf0704f96f427e6148bd0b2848c24f61bbce69"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/4 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-22T20:58:48.679Z","repository_id":57294427,"created_at":"2025-08-22T20:58:48.679Z","updated_at":"2025-08-22T20:58:48.679Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28572573,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T14:39:55.009Z","status":"ssl_error","status_checked_at":"2026-01-19T14:39:01.217Z","response_time":67,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["react","react-component","react-memo","react-performace","react-render","shouldcomponentupdate"],"created_at":"2024-11-20T19:29:19.189Z","updated_at":"2026-01-19T15:01:55.159Z","avatar_url":"https://github.com/qiqiboy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MemoRender\n\nA react-component for optimizing performance when it's parent re-renders.\n\n`MemoRender`是一个非常简单的 react 组件，它是为了某些追求性能场景下，阻止一些已经声明的组件在本身`props`未发生变化（指深度比较 deep diff 后）时频繁重复渲染。\n\n\u003c!-- vim-markdown-toc GFM --\u003e\n\n* [安装](#安装)\n* [如何使用](#如何使用)\n    - [`disabled`](#disabled)\n    - [`deps`](#deps)\n    - [`children`](#children)\n* [原理](#原理)\n* [陷阱](#陷阱)\n\n\u003c!-- vim-markdown-toc --\u003e\n\n## 安装\n\n```bash\n$ npm install memo-render --save\n\n// yarn\n$ yarn add memo-render\n```\n\n## 如何使用\n\n`MemoRender`的使用非常简单，它默认情况下，你只需要将它嵌套包裹需要优化的组件节点即可。它会深度对比子节点对象的变化，以决定是否跳过react渲染。\n\n```diff\n-   \u003cHeavyComponent /\u003e\n+   \u003cMemoRender\u003e\n+       \u003cHeavyComponent /\u003e\n+   \u003c/MemoRender\u003e\n```\n\n### `disabled`\n\n是否启用渲染优化\n\n### `deps`\n\n`deps`是可选的。类似`useMemo` `useCallback`等 hooks 的第二个参数，即需要进行对比的依赖项数组。如果`deps={[]}`，则表示任何情况下都不进行渲染更新。\n\n使用`deps`可以使对比更加高效。\n\n```typescript\n\u003cMemoRender deps={[this.state.name]}\u003e\n    \u003cdiv className={this.state.name}\u003e...\u003c/div\u003e\n\u003c/MemoRender\u003e\n```\n\n### `children`\n\n需要优化的组件节点\n\n## 原理\n\n频繁的重复渲染是大多数事后导致应用下降的原因，而减少渲染这也正是 react 优化性能的最主要方向：[`Avoid Reconciliation`](https://reactjs.org/docs/optimizing-performance.html#avoid-reconciliation) 。大多数时候，我们应当尽可能的通过优化组件划分、组合逻辑、状态模型等，来避免非必要的组件被迫重复渲染。\n\n但是受限于业务形态或者组件维护、业务逻辑限制等原因，有些组件无法从经常更新的上层组件中抽离。所以这时候就需要适用`shouldComponentUpdate`等优化手段了。`shouldComponentUpdate`仅适用于项目本身的组件，对于第三方组件无法适用该方法优化。\n\n而`MemoRender`就是用于这种优化场景，无需改造原有组件，直接将它放到需要优化的节点上层，即可达到一定的优化效果。这是因为组件传递的各种 props（包括 children），大多都是局部临时变量。对于 object 类型数据，局部临时生成，每次都是新的变量对象，这导致 react 内部的 diffing 比较不一致，持续进入下一层组件的`ceconciliation`阶段，即重复渲染。`MemoRender`正式通过深度比较`children`节点是否有变化来告诉 react 是否跳过本次渲染。\n\n感谢`react-fast-compare`，`MemoRender`借助 react 本身的`react.memo`优化技巧，通过深度比较`children`节点，来告诉 react 是否跳过本次渲染。\n\n## 陷阱\n\n\u003e 我们准备了一篇[《高性能表单指南》](https://github.com/qiqiboy/react-formutil/issues/18)，可以了解更多\n\n首先，相信我，绝大多数情况下你都不需要`MemoRender`。\n\n`MemoRender`并不是适用于所有场景，首先第一原则与 `shouldComponentUpdate` / `React.memo` / `React.PureComponent` 的指导思想一致：\n\n**`If the slowdown is noticeable?`**\n\n即，应当仅在应用性能出现明显下降时，再考虑应用这些优化手段。过度优化，可能导致应用存在潜在的 bug（例如组件无法响应 props 或 state 变化的更新）、优化逆反（过度的深度比较可能比 react 本身的 diffing、reconciliation 更慢）等\n\n另外如果`children`节点存在传递了局部内联函数（临时函数），`MemoRender`会无法起到优化作用，甚至起到反作用，导致应用反而更慢。\n\n```typescript\n/**\n * Bad 错误示例\n * 下面两个示例套用MemoRender是无效的，甚至会降低性能\n * 因为 onChange 是一个始终变化的函数，而函数是无法深度比较的\n * 第二个例子虽然传递的options是一个对象，但是因为其包含临时函数属性onChange，因此也会导致优化失效\n */\nfunction APP() {\n    return (\n        \u003cdiv\u003e\n            \u003cMemoRender\u003e\n                \u003cHeavyComponent onChange={() =\u003e {}} /\u003e\n            \u003c/MemoRender\u003e\n\n            \u003cMemoRender\u003e\n                \u003cHeavyComponent options={{ value: 'xx', onChange() {} }} /\u003e\n            \u003c/MemoRender\u003e\n        \u003c/div\u003e\n    );\n}\n```\n\n正确的做法是使用`deps`属性，或者创建不可变的 `onChange` 函数，例如放到组件实例（class 组件）或者适用 memoizeation 优化(function 组件、hooks):\n\n```typescript\n/**\n * Good 优化后\n */\nfunction APP() {\n    const onChange = useCallback(() =\u003e {}, []);\n\n    return (\n        \u003cdiv\u003e\n            \u003cMemoRender\u003e\n                \u003cHeavyComponent onChange={onChange} /\u003e\n                \u003cHeavyComponent options={{ value: 'xx', onChange }} /\u003e\n            \u003c/MemoRender\u003e\n\n            \u003cMemoRender deps={[]}\u003e\n                \u003cHeavyComponent onChange={() =\u003e {}} /\u003e\n            \u003c/MemoRender\u003e\n        \u003c/div\u003e\n    );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiqiboy%2Fmemo-render","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqiqiboy%2Fmemo-render","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiqiboy%2Fmemo-render/lists"}