{"id":338,"date":"2019-12-01T04:17:30","date_gmt":"2019-11-30T20:17:30","guid":{"rendered":"https:\/\/www.oopus.info\/blog\/?p=338"},"modified":"2019-12-01T04:17:30","modified_gmt":"2019-11-30T20:17:30","slug":"%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/","title":{"rendered":"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898"},"content":{"rendered":"\n<p><a href=\"https:\/\/reactjs.org\/docs\/optimizing-performance.html\">https:\/\/reactjs.org\/docs\/optimizing-performance.html<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class CounterButton extends React.Component {\n  constructor(props) {\n    super(props);\n    this.state = {count: 1};\n  }\n\n  shouldComponentUpdate(nextProps, nextState) {\n    if (this.props.color !== nextProps.color) {\n      return true;\n    }\n    if (this.state.count !== nextState.count) {\n      return true;\n    }\n    return false;\n  }\n\n  render() {\n    return (\n      &lt;button\n        color={this.props.color}\n        onClick={() => this.setState(state => ({count: state.count + 1}))}>\n        Count: {this.state.count}\n      &lt;\/button>\n    );\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5728\u8fd9\u6bb5 this.props \u6709\u65f6\u5019\u4ecd\u4f1a\u9020\u6210\u5f02\u6b65\u95ee\u9898\uff0c\u6539\u6210<strong> this.state <\/strong>\u6709\u65f6\u5019\u53ef\u4ee5\u4fee\u590d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (this.props.color !== nextProps.color) {\n  return true;\n}\nif (this.state.count !== nextState.count) {\n  return true;\n}\nreturn false;<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/reactjs.org\/docs\/optimizing-performance.html \u5728\u8fd9\u6bb5 this.props \u6709\u65f6\u5019\u4ecd\u4f1a\u9020\u6210\u5f02\u6b65\u95ee\u9898\uff0c\u6539\u6210 this.state \u6709\u65f6\u5019\u53ef\u4ee5\u4fee\u590d\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[15],"tags":[],"class_list":["post-338","post","type-post","status-publish","format-standard","hentry","category-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898 - Oopus Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/\u7528-shouldcomponentupdate-\u5904\u7406-reactjs-\u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898 - Oopus Blog\" \/>\n<meta property=\"og:description\" content=\"https:\/\/reactjs.org\/docs\/optimizing-performance.html \u5728\u8fd9\u6bb5 this.props \u6709\u65f6\u5019\u4ecd\u4f1a\u9020\u6210\u5f02\u6b65\u95ee\u9898\uff0c\u6539\u6210 this.state \u6709\u65f6\u5019\u53ef\u4ee5\u4fee\u590d\uff1a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/\u7528-shouldcomponentupdate-\u5904\u7406-reactjs-\u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898\/\" \/>\n<meta property=\"og:site_name\" content=\"Oopus Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-30T20:17:30+00:00\" \/>\n<meta name=\"author\" content=\"oopus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"oopus\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/\"},\"author\":{\"name\":\"oopus\",\"@id\":\"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9\"},\"headline\":\"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898\",\"datePublished\":\"2019-11-30T20:17:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/\"},\"wordCount\":12,\"commentCount\":0,\"articleSection\":[\"js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/\",\"url\":\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/\",\"name\":\"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898 - Oopus Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/#website\"},\"datePublished\":\"2019-11-30T20:17:30+00:00\",\"author\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.oopus.info\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.oopus.info\/blog\/#website\",\"url\":\"https:\/\/www.oopus.info\/blog\/\",\"name\":\"Oopus Blog\",\"description\":\"Oopu&#039;s self-recording\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.oopus.info\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9\",\"name\":\"oopus\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g\",\"caption\":\"oopus\"},\"sameAs\":[\"http:\/\/www.oopus.info\/blog\"],\"url\":\"https:\/\/www.oopus.info\/blog\/author\/oopus\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898 - Oopus Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/\u7528-shouldcomponentupdate-\u5904\u7406-reactjs-\u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898\/","og_locale":"en_US","og_type":"article","og_title":"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898 - Oopus Blog","og_description":"https:\/\/reactjs.org\/docs\/optimizing-performance.html \u5728\u8fd9\u6bb5 this.props \u6709\u65f6\u5019\u4ecd\u4f1a\u9020\u6210\u5f02\u6b65\u95ee\u9898\uff0c\u6539\u6210 this.state \u6709\u65f6\u5019\u53ef\u4ee5\u4fee\u590d\uff1a","og_url":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/\u7528-shouldcomponentupdate-\u5904\u7406-reactjs-\u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898\/","og_site_name":"Oopus Blog","article_published_time":"2019-11-30T20:17:30+00:00","author":"oopus","twitter_card":"summary_large_image","twitter_misc":{"Written by":"oopus"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/#article","isPartOf":{"@id":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/"},"author":{"name":"oopus","@id":"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9"},"headline":"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898","datePublished":"2019-11-30T20:17:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/"},"wordCount":12,"commentCount":0,"articleSection":["js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/","url":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/","name":"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898 - Oopus Blog","isPartOf":{"@id":"https:\/\/www.oopus.info\/blog\/#website"},"datePublished":"2019-11-30T20:17:30+00:00","author":{"@id":"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9"},"breadcrumb":{"@id":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.oopus.info\/blog\/2019\/12\/01\/%e7%94%a8-shouldcomponentupdate-%e5%a4%84%e7%90%86-reactjs-%e5%bc%82%e6%ad%a5%e5%9b%9e%e4%bc%a0%e6%95%b0%e6%8d%ae%e4%b9%b1%e5%ba%8f%e7%9a%84%e9%97%ae%e9%a2%98\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.oopus.info\/blog\/"},{"@type":"ListItem","position":2,"name":"\u7528 shouldComponentUpdate \u5904\u7406 reactjs \u5f02\u6b65\u56de\u4f20\u6570\u636e\u4e71\u5e8f\u7684\u95ee\u9898"}]},{"@type":"WebSite","@id":"https:\/\/www.oopus.info\/blog\/#website","url":"https:\/\/www.oopus.info\/blog\/","name":"Oopus Blog","description":"Oopu&#039;s self-recording","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.oopus.info\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.oopus.info\/blog\/#\/schema\/person\/0491ca0bc5ba1f23b62bb7be621f29c9","name":"oopus","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e6169b542ea65ef728fae42c117aa13b4897842f8263161765d1384a2a6e6fd9?s=96&d=mm&r=g","caption":"oopus"},"sameAs":["http:\/\/www.oopus.info\/blog"],"url":"https:\/\/www.oopus.info\/blog\/author\/oopus\/"}]}},"_links":{"self":[{"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/posts\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/comments?post=338"}],"version-history":[{"count":0,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/posts\/338\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/categories?post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oopus.info\/blog\/wp-json\/wp\/v2\/tags?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}