Created
July 29, 2020 13:31
-
-
Save newpost/e641630b21eba0c2c84dd1929aa2b7aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function useUpdateEffect(cb: () => void, depend: any[]) { | |
const [status, setStatus] = useState(false) | |
useEffect(() => { | |
if(status) { | |
cb() | |
} else { | |
setStatus(true) | |
} | |
}, depend) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// 满足只有当依赖发生变化时候才执行cb.第一次时候不会调用cb