Skip to content

Instantly share code, notes, and snippets.

@newpost
Created July 29, 2020 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newpost/e641630b21eba0c2c84dd1929aa2b7aa to your computer and use it in GitHub Desktop.
Save newpost/e641630b21eba0c2c84dd1929aa2b7aa to your computer and use it in GitHub Desktop.
function useUpdateEffect(cb: () => void, depend: any[]) {
const [status, setStatus] = useState(false)
useEffect(() => {
if(status) {
cb()
} else {
setStatus(true)
}
}, depend)
}
@newpost
Copy link
Author

newpost commented Jul 29, 2020

// 满足只有当依赖发生变化时候才执行cb.第一次时候不会调用cb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment