import React from "react";
function memo() {
let template,cache_data;
return function (props) {
if(cache_data===props.data){
return template;
}else{
cache_data=props.data;
return template=<React.Fragment>
{
function () {
console.log("这里只会在加载时触发,更新不会触发");
return props.data.toString();
}()
}
</React.Fragment>
}
}
}
export const Child=memo();
这是我的子组件代码,但是当父组件传入的data不发生改变时,组件是不会触发更新操作的。
由于我用的是react hooks,也就没有shouldComponentUpdate,但是react依然能跳过更新,所以我想知道这是怎么跳过的?