Hacker News new | ask | show | jobs
by underwater 2689 days ago
The pattern of returning an unregister function is a common one. But I agree that the cache key array is strange.

I'd almost suggest that a seperate useEffectOnce function would be better, but I'm sure the abstraction was heavily tested and bikeshedded before it was released in this form.

1 comments

You could create userEffectOnce as a custom hook:

function useEffectOnce(callback) { useEffect(() => { return callback() }, []) }