Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An
enable
option is added as a new third argument, which defaults totrue
. It can be set tofalse
to disable geolocation. The idea is that the option can be flipped totrue
once the user has indicated that they want to be geolocated.This means the hook can be made conditional without violating the rules of hooks and without a conditional nested component which would need to pass its data back up the tree.
Closes #51
Before this changeset, the first argument is a
PositionOptions
object and the second is a callback.I considered a few ways to add this new
enable
option:Should it be a third argument? (non-breaking)
Or extend
PositionOptions
? (probably non-breaking)Or make it the first argument and bump the existing ones to 2 and 3 (breaking)
Or perhaps change the structure completely to an options object, such as
(breaking, unless we add extra code to check for legacy options style)
I went with the first option since it is simplest and non-breaking.
You might consider changing to the scheme in the 4th option or similar in a future major release -- it'd be tidier and more developer-friendly IMO.
After I wrote my test, I found that another test (specifically "useGeolocation when geolocation data is not available handles initial error") broke. This is because a particular mock was left with an implementation after my test which intentionally was not firing, and this mock was not reset before that other test was run, and that other test expected it not to be mocked. So I removed the specific resets, and added a blanket reset all mocks after each test across the whole suite.