`
const [step, setStep] = useState(0);
const [count, setCount] = useState(0);
const handleSetStep = () => {
setStep(step + 1);
};
const handleSetCount = () => {
setCount(count + 1);
};
const lazyCallback = useCallback(() => {
console.log('lazy callback');
return step
}, [step]);
return (
<div>
<button onClick={handleSetStep}>step is : {step} </button>
<button onClick={handleSetCount}>count is : {count} </button>
<hr />
<Child cb={lazyCallback} /> <hr />
</div>
);
`
Childs.jsx
`
export default (props = {}) => {
console.log(`--- re-render ---`);
return (
<div>
<p>number is : {props.cb()}</p>
</div>
);
};
`
lazyCallback只依赖step的变化而变化,为什么我修改count, Child依旧会更新?