I have a situation where I want to run a useInterval function immediately when rendering the hook, but not when its delay is null.
const shouldRun = false;
useInterval(
() => {
// without this, func will run once because of `immediate`, as of v6.0.0
if (!shouldRun) return;
// ...
},
shouldRun ? 50 : null,
// need func to run immediately (not after 50 ms), but only if shouldRun is true
{ immediate: true },
);
As it currently works, immediate will make the func run once even when delay is null. I guess a user could want it this way, but in my opinion, this is unexpected behavior.
It's not a big deal since I can just check shouldRun at the top of the function and early exit, but I'd still bet that most people would be caught off guard by this.
Related: #129
A side note, the controls option could be better documented as "Whether to control interval manually with returned start/stop functions instead of provided delay".
I have a situation where I want to run a
useIntervalfunction immediately when rendering the hook, but not when itsdelayisnull.As it currently works,
immediatewill make the func run once even whendelayisnull. I guess a user could want it this way, but in my opinion, this is unexpected behavior.It's not a big deal since I can just check
shouldRunat the top of the function and early exit, but I'd still bet that most people would be caught off guard by this.Related: #129
A side note, the
controlsoption could be better documented as "Whether to control interval manually with returned start/stop functions instead of provided delay".