{"id":123092,"date":"2026-11-06T11:32:55","date_gmt":"2026-11-06T03:32:55","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/123092.html"},"modified":"2026-11-06T11:32:55","modified_gmt":"2026-11-06T03:32:55","slug":"%e7%88%b6%e7%bb%84%e4%bb%b6setstate%ef%bc%8c%e5%ad%90%e7%bb%84%e4%bb%b6%e4%b8%ba%e4%bd%95%e4%bb%8d%e9%87%8d%e6%b8%b2%e6%9f%93%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/123092.html","title":{"rendered":"\u7236\u7ec4\u4ef6setState\uff0c\u5b50\u7ec4\u4ef6\u4e3a\u4f55\u4ecd\u91cd\u6e32\u67d3\uff1f"},"content":{"rendered":"<p>        \/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/<br \/>\n        #content_views .toc,<br \/>\n        \/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/<br \/>\n        #content_views.markdown_views &gt; p:empty:has(+ .toc),<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty,<br \/>\n        \/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/<br \/>\n        #content_views.htmledit_views #main-toc,<br \/>\n        #content_views.htmledit_views #hr-toc,<br \/>\n        #content_views.htmledit_views p[id*=\\&#8221;-toc\\&#8221;] {<br \/>\n          display: none !important;<br \/>\n        }<br \/>\n        \/* \u76ee\u5f55\u53bb\u6389\u540e\uff0c\u7d27\u8ddf\u7684\u9996\u4e2a\u6807\u9898\u4e0d\u518d\u591a\u51fa\u4e00\u5757\u4e0a\u8fb9\u8ddd *\/<br \/>\n        #content_views.markdown_views &gt; .toc + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + h4,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h4 {<br \/>\n          margin-top: 0 !important;<br \/>\n        }<\/p>\n<p>import React,{Component} from &#039;react&#039;;<br \/>\nimport &#039;.\/index.css&#039;;<\/p>\n<p>export default class Demo extends Component{<br \/>\n    state &#061; {<br \/>\n        count: 100,<br \/>\n    }<br \/>\n    render(){<br \/>\n        console.log(&#039;\u7236\u7ec4\u4ef6\u6e32\u67d3&#039;);<\/p>\n<p>        return (<br \/>\n            &lt;div className&#061;&#034;father&#034;&gt;<br \/>\n                &lt;h1&gt;\u6211\u662f\u7236\u7ec4\u4ef6&lt;\/h1&gt;<br \/>\n                &lt;p className&#061;&#034;count&#034;&gt;\u5f53\u524d\u8ba1\u6570: {this.state.count}&lt;\/p&gt;<br \/>\n                &lt;button onClick&#061;{() &#061;&gt; this.setState({count: this.state.count &#043; 1})}&gt;\u589e\u52a0&lt;\/button&gt;<br \/>\n                &lt;Child count&#061;{this.state.count} \/&gt;<br \/>\n            &lt;\/div&gt;<br \/>\n        )<br \/>\n    }<br \/>\n}<\/p>\n<p>class Child extends Component{<br \/>\n    render(){<br \/>\n        console.log(&#039;\u5b50\u7ec4\u4ef6\u6e32\u67d3&#039;);<\/p>\n<p>        return (<br \/>\n            &lt;div className&#061;&#034;child&#034;&gt;<br \/>\n                &lt;h1&gt;\u6211\u662f\u5b50\u7ec4\u4ef6&lt;\/h1&gt;<br \/>\n                &lt;p className&#061;&#034;count&#034;&gt;\u5f53\u524d\u8ba1\u6570: {this.props.count}&lt;\/p&gt;<br \/>\n            &lt;\/div&gt;<br \/>\n        )<br \/>\n    }<br \/>\n}<\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5f53\u521d\u6b21\u6e32\u67d3\u65f6&#xff0c;\u540e\u53f0\u6253\u5370<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"66\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261106033252-6aed4a64e3657.png\" width=\"769\" \/><\/p>\n<p>\u5f53\u6e32\u67d3\u5230\u7236\u7ec4\u4ef6\u65f6&#xff0c;\u6267\u884crender&#xff0c;\u6253\u5370&#xff1b;\u6267\u884c\u5230<span style=\"color:#fe2c24\">&lt;Child count&#061;{this.state.count} \/&gt;\u00a0<\/span>\u65f6&#xff0c;\u518d\u53bb\u6267\u884c\u5b50\u7ec4\u4ef6\u4e2d\u7684render&#xff0c;\u6253\u5370\u3002\u8fd9\u662f\u5b8c\u5168\u6b63\u5e38\u7684\u6d41\u7a0b\u3002<\/p>\n<p>\u5f53\u7236\u7ec4\u4ef6\u6267\u884c<span style=\"color:#fe2c24\">&lt;button onClick&#061;{() &#061;&gt; this.setState({count: this.state.count &#043; 1})}&gt;\u589e\u52a0&lt;\/button&gt;\u00a0\u65f6<\/span>&#xff0c;\u7236\u7ec4\u4ef6\u7684\u72b6\u6001\u53d1\u751f\u6539\u53d8&#xff0c;\u89e6\u53d1render&#xff0c;\u6253\u5370&#xff0c;\u8fdb\u800c\u5b50\u7ec4\u4ef6\u4e5f\u4f1a\u89e6\u53d1render<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"456\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261106033253-6aed4a651d588.png\" width=\"1795\" \/><\/p>\n<p>\u90a3\u5f53\u6211\u4e0d\u5411\u5b50\u7ec4\u4ef6\u4f20\u9012\u4efb\u4f55\u503c&#xff0c;\u5f53\u6211\u6267\u884c\u7236\u7ec4\u4ef6\u4e2d\u7684\u6539\u53d8count\u7684\u65b9\u6cd5\u65f6&#xff0c;\u4e24\u4e2a\u7ec4\u4ef6\u4f1a\u90fd\u6253\u5370\u5417&#xff1f;<\/p>\n<p>import React,{Component} from &#039;react&#039;;<br \/>\nimport &#039;.\/index.css&#039;;<\/p>\n<p>export default class Demo extends Component{<br \/>\n    state &#061; {<br \/>\n        count: 100,<br \/>\n    }<br \/>\n    render(){<br \/>\n        console.log(&#039;\u7236\u7ec4\u4ef6\u6e32\u67d3&#039;);<\/p>\n<p>        return (<br \/>\n            &lt;div className&#061;&#034;father&#034;&gt;<br \/>\n                &lt;h1&gt;\u6211\u662f\u7236\u7ec4\u4ef6&lt;\/h1&gt;<br \/>\n                &lt;p className&#061;&#034;count&#034;&gt;\u5f53\u524d\u8ba1\u6570: {this.state.count}&lt;\/p&gt;<br \/>\n                &lt;button onClick&#061;{() &#061;&gt; this.setState({count: this.state.count &#043; 1})}&gt;\u589e\u52a0&lt;\/button&gt;<br \/>\n                &lt;Child \/&gt;<br \/>\n            &lt;\/div&gt;<br \/>\n        )<br \/>\n    }<br \/>\n}<\/p>\n<p>class Child extends Component{<br \/>\n    render(){<br \/>\n        console.log(&#039;\u5b50\u7ec4\u4ef6\u6e32\u67d3&#039;);<\/p>\n<p>        return (<br \/>\n            &lt;div className&#061;&#034;child&#034;&gt;<br \/>\n                &lt;h1&gt;\u6211\u662f\u5b50\u7ec4\u4ef6&lt;\/h1&gt;<br \/>\n                {\/* &lt;p className&#061;&#034;count&#034;&gt;\u5f53\u524d\u8ba1\u6570: {this.props.count}&lt;\/p&gt; *\/}<br \/>\n            &lt;\/div&gt;<br \/>\n        )<br \/>\n    }<br \/>\n}<\/p>\n<p>\u7ed3\u679c\u5c31\u662f&#xff0c;\u5b50\u7ec4\u4ef6\u7167\u6837\u4f1a\u6267\u884crender&#xff0c;\u91cd\u65b0\u8fdb\u884c\u6e32\u67d3\u3002\u800c\u4e14\u5f53\u7236\u7ec4\u4ef6\u6267\u884c\u00a0<span style=\"color:#fe2c24\">this.setState({})<\/span>\u00a0\u7167\u6837\u4f1a\u51fa\u73b0\u76f8\u540c\u7684\u6548\u679c<\/p>\n<p>\u5b50\u7ec4\u4ef6\u6211\u53ea\u662f\u60f3\u5c55\u793a\u4e00\u4e0b&#xff0c;\u53ea\u662f\u7236\u7ec4\u4ef6\u7684\u72b6\u6001\u6539\u53d8\u4e86&#xff0c;\u4ed6\u6267\u884crender\u5b8c\u5168\u6ca1\u6709\u95ee\u9898&#xff0c;\u4f46\u662f\u5b50\u7ec4\u4ef6\u518d\u91cd\u65b0\u6e32\u67d3\u5c31\u6709\u70b9\u8017\u6027\u80fd\u4e86\u3002<\/p>\n<h3>Component\u76842\u4e2a\u95ee\u9898<\/h3>\n<p>1\u3001\u53ea\u8981\u6267\u884csetState(),\u5373\u4f7f\u4e0d\u6539\u53d8\u72b6\u6001\u6570\u636e&#xff0c;\u7ec4\u4ef6\u4e5f\u4f1a\u91cd\u65b0render(),\u6548\u7387\u4f4e<\/p>\n<p>2\u3001\u53ea\u5f53\u524d\u7ec4\u4ef6\u91cd\u65b0render(),\u5c31\u4f1a\u91cd\u65b0render\u5b50\u7ec4\u4ef6&#xff0c;\u7eb5\u4f7f\u5b50\u7ec4\u4ef6\u6ca1\u6709\u7528\u5230\u7236\u7ec4\u4ef6\u7684\u4efb\u4f55\u6570\u636e<\/p>\n<h3>\u6548\u7387\u9ad8\u7684\u505a\u6cd5<\/h3>\n<p>\u53ea\u6709\u5f53\u524d\u7ec4\u4ef6\u7684state\u6216props\u6570\u636e\u53d1\u751f\u6539\u53d8\u65f6\u624d\u91cd\u65b0render()<\/p>\n<h3>\u539f\u56e0<\/h3>\n<p>Component\u4e2d\u7684shouldComponentUpdate()\u603b\u662f\u8fd4\u56detrue<\/p>\n<h3>\u89e3\u51b3\u65b9\u6cd5\u4e00<\/h3>\n<p>\u91cd\u5199shouldComponentUpdate\u65b9\u6cd5&#xff0c;\u6bd4\u8f83\u65b0\u65e7state\u6216props\u6570\u636e&#xff0c;\u5982\u679c\u6709\u53d8\u5316\u53c2\u8fd4\u56detrue&#xff0c;\u5982\u679c\u6ca1\u6709\u5219\u8fd4\u56defalse<\/p>\n<p>import React,{Component} from &#039;react&#039;;<br \/>\nimport &#039;.\/index.css&#039;;<\/p>\n<p>export default class Demo extends Component{<br \/>\n    state &#061; {<br \/>\n        count: 100,<br \/>\n    }<\/p>\n<p>    shouldComponentUpdate(nextProps, nextState){<br \/>\n        \/\/nextProps: \u4e0b\u4e00\u4e2a props<br \/>\n        \/\/nextState: \u4e0b\u4e00\u4e2a state<br \/>\n        \/\/\u8fd4\u56de\u503c: true \u8868\u793a\u7ec4\u4ef6\u9700\u8981\u91cd\u65b0\u6e32\u67d3&#xff0c;false \u8868\u793a\u4e0d\u9700\u8981\u91cd\u65b0\u6e32\u67d3<br \/>\n        console.log(nextProps, nextState);<br \/>\n        \/\/\u5982\u679c\u4e0b\u4e00\u4e2a props \u6216\u4e0b\u4e00\u4e2a state \u4e0e\u5f53\u524d props \u6216\u5f53\u524d state \u76f8\u540c&#xff0c;\u8fd4\u56de false<br \/>\n        \/\/\u5982\u679c\u4e0b\u4e00\u4e2a props \u6216\u4e0b\u4e00\u4e2a state \u4e0e\u5f53\u524d props \u6216\u5f53\u524d state \u4e0d\u540c&#xff0c;\u8fd4\u56de true<br \/>\n        if(nextState.count !&#061;&#061; this.state.count){<br \/>\n            return true;<br \/>\n        }<br \/>\n        return false;<br \/>\n        \/\/ return nextState.count !&#061;&#061; this.state.count;<br \/>\n    }<\/p>\n<p>    render(){<br \/>\n        console.log(&#039;\u7236\u7ec4\u4ef6\u6e32\u67d3&#039;);<\/p>\n<p>        return (<br \/>\n            &lt;div className&#061;&#034;father&#034;&gt;<br \/>\n                &lt;h1&gt;\u6211\u662f\u7236\u7ec4\u4ef6&lt;\/h1&gt;<br \/>\n                &lt;p className&#061;&#034;count&#034;&gt;\u5f53\u524d\u8ba1\u6570: {this.state.count}&lt;\/p&gt;<br \/>\n                &lt;button onClick&#061;{() &#061;&gt; this.setState({ count: this.state.count &#043; 100 })}&gt;\u589e\u52a0&lt;\/button&gt;<br \/>\n                {\/* &lt;Child \/&gt; *\/}<br \/>\n            &lt;\/div&gt;<br \/>\n        )<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ class Child extends Component{<br \/>\n\/\/     render(){<br \/>\n\/\/         console.log(&#039;\u5b50\u7ec4\u4ef6\u6e32\u67d3&#039;);<\/p>\n<p>\/\/         return (<br \/>\n\/\/             &lt;div className&#061;&#034;child&#034;&gt;<br \/>\n\/\/                 &lt;h1&gt;\u6211\u662f\u5b50\u7ec4\u4ef6&lt;\/h1&gt;<br \/>\n\/\/                 {\/* &lt;p className&#061;&#034;count&#034;&gt;\u5f53\u524d\u8ba1\u6570: {this.props.count}&lt;\/p&gt; *\/}<br \/>\n\/\/             &lt;\/div&gt;<br \/>\n\/\/         )<br \/>\n\/\/     }<br \/>\n\/\/ }<\/p>\n<p>\u5f53\u7236\u7ec4\u4ef6\u6267\u884c\u65b9\u6cd5&#xff0c;\u6539\u53d8\u72b6\u6001\u503c&#xff0c;\u4e5f\u89e6\u53d1render&#xff0c;\u5b8c\u5168\u6b63\u786e\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"479\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261106033253-6aed4a6571385.png\" width=\"1792\" \/><\/p>\n<p>\u5f53\u6267\u884c this.setState({})\u5462&#xff1f;<\/p>\n<p> &lt;button onClick&#061;{() &#061;&gt; this.setState({})}&gt;\u589e\u52a0&lt;\/button&gt;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"483\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261106033253-6aed4a65d6f06.png\" width=\"1796\" \/><\/p>\n<p>\u7236\u7ec4\u4ef6\u7684\u72b6\u6001\u5728\u524d\u540e\u90fd\u6ca1\u6709\u53d1\u751f\u53d8\u5316&#xff0c;\u81ea\u7136\u4e0d\u4f1a\u91cd\u65b0render&#xff0c;\u8fbe\u5230\u4e86\u63d0\u5347\u6548\u7387\u7684\u76ee\u7684\u3002<\/p>\n<p>\u540c\u7406\u5b50\u7ec4\u4ef6\u4e5f\u53ef\u4ee5\u8fd9\u6837\u505a<\/p>\n<p>import React,{Component} from &#039;react&#039;;<br \/>\nimport &#039;.\/index.css&#039;;<\/p>\n<p>export default class Demo extends Component{<br \/>\n    state &#061; {<br \/>\n        count: 100,<br \/>\n    }<\/p>\n<p>    shouldComponentUpdate(nextProps, nextState){<br \/>\n        \/\/nextProps: \u4e0b\u4e00\u4e2a props<br \/>\n        \/\/nextState: \u4e0b\u4e00\u4e2a state<br \/>\n        \/\/\u8fd4\u56de\u503c: true \u8868\u793a\u7ec4\u4ef6\u9700\u8981\u91cd\u65b0\u6e32\u67d3&#xff0c;false \u8868\u793a\u4e0d\u9700\u8981\u91cd\u65b0\u6e32\u67d3<br \/>\n        console.log(nextProps, nextState);<br \/>\n        \/\/\u5982\u679c\u4e0b\u4e00\u4e2a props \u6216\u4e0b\u4e00\u4e2a state \u4e0e\u5f53\u524d props \u6216\u5f53\u524d state \u76f8\u540c&#xff0c;\u8fd4\u56de false<br \/>\n        \/\/\u5982\u679c\u4e0b\u4e00\u4e2a props \u6216\u4e0b\u4e00\u4e2a state \u4e0e\u5f53\u524d props \u6216\u5f53\u524d state \u4e0d\u540c&#xff0c;\u8fd4\u56de true<br \/>\n        if(nextState.count !&#061;&#061; this.state.count){<br \/>\n            return true;<br \/>\n        }<br \/>\n        return false;<br \/>\n        \/\/ return nextState.count !&#061;&#061; this.state.count;<br \/>\n    }<\/p>\n<p>    render(){<br \/>\n        console.log(&#039;\u7236\u7ec4\u4ef6\u6e32\u67d3&#039;);<\/p>\n<p>        return (<br \/>\n            &lt;div className&#061;&#034;father&#034;&gt;<br \/>\n                &lt;h1&gt;\u6211\u662f\u7236\u7ec4\u4ef6&lt;\/h1&gt;<br \/>\n                &lt;p className&#061;&#034;count&#034;&gt;\u5f53\u524d\u8ba1\u6570: {this.state.count}&lt;\/p&gt;<br \/>\n                &lt;button onClick&#061;{() &#061;&gt; this.setState({ count: this.state.count &#043; 100 })}&gt;\u589e\u52a0&lt;\/button&gt;<br \/>\n                &lt;Child count&#061;{this.state.count} \/&gt;<br \/>\n            &lt;\/div&gt;<br \/>\n        )<br \/>\n    }<br \/>\n}<\/p>\n<p>class Child extends Component{<br \/>\n    shouldComponentUpdate(nextProps, nextState){<br \/>\n        \/\/nextProps: \u4e0b\u4e00\u4e2a props<br \/>\n        \/\/nextState: \u4e0b\u4e00\u4e2a state<br \/>\n        \/\/\u8fd4\u56de\u503c: true \u8868\u793a\u7ec4\u4ef6\u9700\u8981\u91cd\u65b0\u6e32\u67d3&#xff0c;false \u8868\u793a\u4e0d\u9700\u8981\u91cd\u65b0\u6e32\u67d3<br \/>\n        if(nextProps.count !&#061;&#061; this.props.count){<br \/>\n            return true;<br \/>\n        }<br \/>\n        return false;<br \/>\n        \/\/ return nextState.count !&#061;&#061; this.state.count;<br \/>\n    }<br \/>\n    render(){<br \/>\n        console.log(&#039;\u5b50\u7ec4\u4ef6\u6e32\u67d3&#039;);<\/p>\n<p>        return (<br \/>\n            &lt;div className&#061;&#034;child&#034;&gt;<br \/>\n                &lt;h1&gt;\u6211\u662f\u5b50\u7ec4\u4ef6&lt;\/h1&gt;<br \/>\n                &lt;p className&#061;&#034;count&#034;&gt;\u5f53\u524d\u8ba1\u6570: {this.props.count}&lt;\/p&gt;<br \/>\n            &lt;\/div&gt;<br \/>\n        )<br \/>\n    }<br \/>\n}<\/p>\n<p>\u6ce8\u610f\u7684\u662f&#xff0c;\u5f53\u7236\u7ec4\u4ef6\u6267\u884c\u00a0this.setState({})\u00a0\u6216\u8005\u4e0d\u7ed9\u5b50\u7ec4\u4ef6\u4f20\u9012\u503c\u00a0&lt;Child \/&gt;&#xff0c;\u5b50\u7ec4\u4ef6\u90fd\u4e0d\u4f1a\u66f4\u65b0\u503c\u7684\u3002<\/p>\n<h4>\u7279\u522b\u6ce8\u610f<\/h4>\n<p>import React,{Component} from &#039;react&#039;;<br \/>\nimport &#039;.\/index.css&#039;;<\/p>\n<p>export default class Demo extends Component{<br \/>\n    state &#061; {<br \/>\n        count: 100,<br \/>\n        stu:[&#039;\u5f20\u4e09&#039;,&#039;\u674e\u56db&#039;,&#039;\u738b\u4e94&#039;]<br \/>\n    }<\/p>\n<p>    shouldComponentUpdate(nextProps, nextState){<br \/>\n        \/\/nextProps: \u4e0b\u4e00\u4e2a props<br \/>\n        \/\/nextState: \u4e0b\u4e00\u4e2a state<br \/>\n        \/\/\u8fd4\u56de\u503c: true \u8868\u793a\u7ec4\u4ef6\u9700\u8981\u91cd\u65b0\u6e32\u67d3&#xff0c;false \u8868\u793a\u4e0d\u9700\u8981\u91cd\u65b0\u6e32\u67d3<br \/>\n        console.log(nextProps, nextState);<br \/>\n        \/\/\u5982\u679c\u4e0b\u4e00\u4e2a props \u6216\u4e0b\u4e00\u4e2a state \u4e0e\u5f53\u524d props \u6216\u5f53\u524d state \u76f8\u540c&#xff0c;\u8fd4\u56de false<br \/>\n        \/\/\u5982\u679c\u4e0b\u4e00\u4e2a props \u6216\u4e0b\u4e00\u4e2a state \u4e0e\u5f53\u524d props \u6216\u5f53\u524d state \u4e0d\u540c&#xff0c;\u8fd4\u56de true<br \/>\n        if(nextState.count !&#061;&#061; this.state.count){<br \/>\n            return true;<br \/>\n        }<br \/>\n        if(nextState.stu !&#061;&#061; this.state.stu){<br \/>\n            return true;<br \/>\n        }<br \/>\n        return false;<br \/>\n        \/\/ return nextState.count !&#061;&#061; this.state.count;<br \/>\n    }<br \/>\n    addStu(){<br \/>\n       const {stu} &#061; this.state;<br \/>\n       stu.push(&#039;\u8d75\u516d&#039;);<br \/>\n       this.setState({<br \/>\n            stu<br \/>\n       })<br \/>\n    }<\/p>\n<p>    render(){<br \/>\n        console.log(&#039;\u7236\u7ec4\u4ef6\u6e32\u67d3&#039;);<\/p>\n<p>        return (<br \/>\n            &lt;div className&#061;&#034;father&#034;&gt;<br \/>\n                &lt;h1&gt;\u6211\u662f\u7236\u7ec4\u4ef6&lt;\/h1&gt;<br \/>\n                &lt;p className&#061;&#034;count&#034;&gt;\u5f53\u524d\u8ba1\u6570: {this.state.count}&lt;\/p&gt;<br \/>\n                &lt;p className&#061;&#034;stu&#034;&gt;\u5f53\u524d\u5b66\u751f: {this.state.stu.join(&#039;\u3001&#039;)}&lt;\/p&gt;<br \/>\n                &lt;button onClick&#061;{() &#061;&gt; this.setState({ count: this.state.count &#043; 100 })}&gt;\u589e\u52a0&lt;\/button&gt;<br \/>\n                &lt;button onClick&#061;{() &#061;&gt; this.addStu()}&gt;\u589e\u52a0\u5b66\u751f&lt;\/button&gt;<br \/>\n            &lt;\/div&gt;<br \/>\n        )<br \/>\n    }<br \/>\n}<\/p>\n<p>    addStu(){<br \/>\n       const {stu} &#061; this.state;<br \/>\n       stu.push(&#039;\u8d75\u516d&#039;);<br \/>\n       this.setState({<br \/>\n            stu<br \/>\n       })<br \/>\n    }<\/p>\n<p>    if(nextState.stu !&#061;&#061; this.state.stu){<br \/>\n            return true;<br \/>\n        }<\/p>\n<p>\u662f\u89e6\u53d1\u4e0d\u4e86\u66f4\u65b0\u7684&#xff0c;\u56e0\u4e3a\u7ed3\u6784\u51fa\u6765\u7684stu\u867d\u7136\u503c\u53d8\u4e86&#xff0c;\u4f46\u662fshouldComponentUpdate\u5224\u65ad\u4e2dnextState.stu\u548cthis.state.stu\u7684\u5730\u5740\u503c\u662f\u524d\u540e\u76f8\u540c\u7684&#xff0c;\u8fdb\u800c\u4e0d\u4f1a\u89e6\u53d1render&#xff0c;\u5373\u4fbfnextState\u5728\u53d8\u5316&#xff0c;<\/p>\n<p>\u8981\u60f3\u89e3\u51b3\u8fd9\u4e2a\u9ebb\u70e6\u53ef\u4ee5\u8fd9\u6837\u89e3\u51b3<\/p>\n<p>    addStu(){<br \/>\n        this.setState({<br \/>\n            stu: [&#8230;this.state.stu, &#039;\u8d75\u516d&#039;]<br \/>\n        })<br \/>\n    }<\/p>\n<p>\u7c7b\u4f3cpush\u548cshift\u7684\u64cd\u4f5c\u9700\u8981\u4e0b&#xff01;&#xff01;&#xff01;<\/p>\n<p>\u5355\u72ec\u5199<\/p>\n<p>    if(nextState.stu.join(&#039;,&#039;) !&#061;&#061; this.state.stu.join(&#039;,&#039;)){<br \/>\n            return true;<br \/>\n        }<\/p>\n<p>\u4e5f\u662f\u89e3\u51b3\u4e0d\u4e86\u7684<\/p>\n<h3>\u89e3\u51b3\u65b9\u6cd5\u4e8c<\/h3>\n<p>\u4f7f\u7528 PureComponent\u4ee3\u66ffComponent\u6765\u8ba9\u7ec4\u4ef6\u7ee7\u627f&#xff0c;\u5b83\u91cd\u5199\u4e86shouldComponentUpdate(),\u53ea\u6709state\u548cprops\u6570\u636e\u6709\u53d8\u5316\u624d\u8fd4\u56detrue<\/p>\n<h4>\u6ce8\u610f<\/h4>\n<p>\u53ea\u662f\u8fdb\u884cstate\u548cprops\u6570\u636e\u7684\u8bd5\u6bd4\u8f83&#xff0c;\u5982\u679c\u53ea\u662f\u6570\u636e\u5bf9\u8c61\u5185\u90e8\u6570\u636e\u53d8\u4e86&#xff0c;\u8fd4\u56defalse<\/p>\n<p>\u4e0d\u8981\u76f4\u63a5\u4fee\u6539\u6570\u636e&#xff0c;\u800c\u662f\u4ea7\u751f\u65b0\u6570\u636e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content<\/p>\n","protected":false},"author":2,"featured_media":123088,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[187,524,87,190],"topic":[],"class_list":["post-123092","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-javascript","tag-react-js","tag-87","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7236\u7ec4\u4ef6setState\uff0c\u5b50\u7ec4\u4ef6\u4e3a\u4f55\u4ecd\u91cd\u6e32\u67d3\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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.wsisp.com\/helps\/123092.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7236\u7ec4\u4ef6setState\uff0c\u5b50\u7ec4\u4ef6\u4e3a\u4f55\u4ecd\u91cd\u6e32\u67d3\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/123092.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-06T03:32:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261106033252-6aed4a64e3657.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/123092.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/123092.html\",\"name\":\"\u7236\u7ec4\u4ef6setState\uff0c\u5b50\u7ec4\u4ef6\u4e3a\u4f55\u4ecd\u91cd\u6e32\u67d3\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-11-06T03:32:55+00:00\",\"dateModified\":\"2026-11-06T03:32:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/123092.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/123092.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/123092.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7236\u7ec4\u4ef6setState\uff0c\u5b50\u7ec4\u4ef6\u4e3a\u4f55\u4ecd\u91cd\u6e32\u67d3\uff1f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7236\u7ec4\u4ef6setState\uff0c\u5b50\u7ec4\u4ef6\u4e3a\u4f55\u4ecd\u91cd\u6e32\u67d3\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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.wsisp.com\/helps\/123092.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7236\u7ec4\u4ef6setState\uff0c\u5b50\u7ec4\u4ef6\u4e3a\u4f55\u4ecd\u91cd\u6e32\u67d3\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content","og_url":"https:\/\/www.wsisp.com\/helps\/123092.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-11-06T03:32:55+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261106033252-6aed4a64e3657.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/123092.html","url":"https:\/\/www.wsisp.com\/helps\/123092.html","name":"\u7236\u7ec4\u4ef6setState\uff0c\u5b50\u7ec4\u4ef6\u4e3a\u4f55\u4ecd\u91cd\u6e32\u67d3\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-11-06T03:32:55+00:00","dateModified":"2026-11-06T03:32:55+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/123092.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/123092.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/123092.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7236\u7ec4\u4ef6setState\uff0c\u5b50\u7ec4\u4ef6\u4e3a\u4f55\u4ecd\u91cd\u6e32\u67d3\uff1f"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/123092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=123092"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/123092\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/123088"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=123092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=123092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=123092"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=123092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}