react hooks useCallback问题?

`

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 (
    


);

`

Childs.jsx
`

export default (props = {}) => {
    console.log(`--- re-render ---`);
    return (
        

number is : {props.cb()}

); };

`

lazyCallback只依赖step的变化而变化,为什么我修改count, Child依旧会更新?

最佳答案

Child更新不是因为lazyCallback变了,而是因为父组件re-render了,进而造成子组件(Child)re-render