Closed ftreedom closed 1 year ago
Can you explain why passing an undefined variable to the hook is problematic? I think it’s idiomatic that functions should treat foo()
and foo(undefinedVar)
the same and both should be allowed by the type.
Users should be responsible for managing values they pass in rather than assuming every API is going to cast.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi everyone,
I've encountered a strange behavior with useEffectOnceWhen today with a component like this:
The condition was fired every time despite the fact that the component was rendered like this:
<ExampleComponent />
After some debugging and taking a closer look at the code I've noticed thatcondition
prop is optional, and the current type declaration onuseEffectOnceWhen
is not really helpful in this case.This is the current type definition of useEffectOnceWhen:
declare function useEffectOnceWhen(callback: () => void, when?: boolean): void;
I would suggest changing it like this:
declare function useEffectOnceWhen(callback: () => void): void
declare function useEffectOnceWhen(callback: () => void, when: boolean): void
This could be helpful to ensure that if a condition is passed, its value would be boolean.
I wanted to be sure that this could be an improvement for you all before opening a PR.