3 ms·
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 useEffectO
by underwater 8y 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.
- feralfoo 8y agoYou could create userEffectOnce as a custom hook: function useEffectOnce(callback) { useEffect(() => { return callback() }, []) }