其他分享
首页 > 其他分享> > react hooks useMemo和useCallback

react hooks useMemo和useCallback

作者:互联网

export default () => {
    const [count, setCount] = useState(0);
    const isEvenNumber = useMemo(()=>{
        return count % 2 === 0
    }, [count])

    const onClick = useCallback(()=>{
        setCount(count+1)
    },[count])

    return (<div>
        <div>{count} is {isEvenNumber? 'even':'odd'} number</div>
        <button onClick={onClick}>click me</button>
    </div>)
}

标签:count,const,useMemo,hooks,isEvenNumber,useCallback,react,return
来源: https://www.cnblogs.com/chengyunshen/p/14810171.html