react中useCallback使用
作者:互联网
import React ,{useState,useCallback,memo} from 'react'
const Child = memo((props) =>{
console.log('child run ...');
return(
<>
<h1>hello</h1>
<button onclick="{props.onAdd}">add</button>
)
})
export default function UseCallback() {
console.log('parent run ...');
let [count, setCount] = useState(0)
const handAdd = useCallback(
() =>{
console.log('父组件里的handAdd执行了。。。。');
},
[],
)
// const handAdd = () =>{
// console.log('父组件里的handAdd执行了。。。。');
// }
return (
<div>
<h2>{count}</h2>
<child onadd="{handAdd}">
<button onclick="{()" ==""> setCount(100)}>changeCount</button>
</child></div>
)
}
标签:console,log,handAdd,react,useState,使用,const,useCallback 来源: https://www.cnblogs.com/malong1992/p/15365250.html