usePopState has wrong type definition, hook dependencies
See original GitHub issueHey again!
So I have a use-case where a modal dialog contains links and the modal needs to close on any history change.
Rather than making my own listener, I went to see how raviger
implements it, and found the nifty usePopState
hook that does pretty much what I need. However I found the following:
-
usePopState
is exposed but has no entry in the documentation. Is it part of the API? Is it fine to use it? -
In the type definition, it says that the
predicate
parameter is a function that returns a boolean, however, according to the actual implementation and usages across the library, it seems that it’s only expecting a boolean. -
The
predicate
parameter is not added to the dependencies of theuseEffect
hook, which means that if we need to change that condition after the initial render, it won’t be taken into account. -
I feel that
predicate
should be an optional argument, and could be moved to being the third parameter? -
Probably have the same feeling about the first parameter. Seems like
basePath
could be optional and default to''
.
Looking forward to hearing about your opinion on these 👍
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Hey @yenoiwesa 👋
basePath
, if one exists. But then if you want to opt-out its awkward. But otherwise most times you will be callingusePopState(useBathPath())
, which is also awkward. This needs more thought.@yenoiwesa Check out #29 and let me know what you think.
Its published with the first release candidate