New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add useNetInfoInstance - a non singleton-state hook to manage configs / events independently #687
feat: add useNetInfoInstance - a non singleton-state hook to manage configs / events independently #687
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting - these seems fine (and like a nice fix for the issue you link)
Do you think this qualifies as a breaking change? You've maintained the old implementation for people that really need compatibility (for whatever reason) but as a new name - what I'm not sure about is if there is some case where the new implementation under the old name will actually change functionality for existing people, or if it will simply behave better in almost every way
Any answer is correct - please just let me know - the only difference is whether the release gets a semver major with a breaking changes note that people needing <insert very specific behavior criteria here from old implementation>
should use the useNetInfoSingleton
API name or whether it is just a semver minor
Yeah good point thanks, I think it could definitely break peoples existing usage of it. It's probably best to stay on the safer side and keep existing behaviour for people and create a newly named hook for this functionality. The naming isn't obvious to me all I got is I'd also like to add the ability to pause the hook, so something like this:
|
useNetInfoInstance seems as good as anything? Naming is impossible - but that seems good enough to me. If it's not perturbing existing functionality, the sky's the limit on implementation really |
03ec79b
to
a7ec537
Compare
Cool, have updated the PR. Thanks for reviewing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only quibble now is lack of documentation, so this capability (and the pro and con of using it) won't be discoverable for people at all. Writing docs is no fun but as motivation, the more people using your code, the more people to find+fix things they see before you even see them, resulting in the code working better for you as well. Vs you being solo in this code path :-)
If you could maybe take the second two stanzas here (subscribe/get) and put them under a new "Global shared state style" header (or whatever sounds good to you for naming) then add a new "Hook-managed state style" header (or, whatever sounds good for naming) then describe the new instance hook and how + why you would use it?
It occurs to me that the useNetInfo existing hook has no documentation at all so maybe adding a quick mention up in the global shared style subscribe section...
a7ec537
to
23478d4
Compare
23478d4
to
54bfae8
Compare
Thanks @mikehardy, I've just pushed the doc changes, let me know what you think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation addition looks amazing! Seriously, that's a major improvement. Thank you
# [11.1.0](v11.0.1...v11.1.0) (2023-11-08) ### Features * add useNetInfoInstance - a non singleton-state hook to manage configs / events independently ([#687](#687)) ([ca4c586](ca4c586))
🎉 This PR is included in version 11.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Overview
The objective here is to allow consumption of this library without the global singleton. I am currently experiencing a bug where this library is continuing to check the network status in the background and then when my app comes back into foreground and I retrieve the state from netinfo, it's saying there's no connection. This is because the netinfo singleton is running in the background and the network request eventually gets blocked by iOS. see issue Issue #669. It would be nice to pause checking the status when ever my app goes into the background. ie
useNetInfo({isPaused: true})
. It would nice for all network checking to stop ifuseNetInfo
is unmounted.This library manages a singleton which is beneficial in some cases but not ideal in others:
useNetInfo
need to cause all other hooks to break? When everuseNetInfo
is called with a config, the existing singleton is torn down and other hooks will stop receiving updates.useNetInfo
is unmounted, the singleton continues to run, whenuseNetInfo
is re-mounted, it just taps back into the currently running singleton.useNetInfo
hooks is not following reacts principle of Hooks let you share stateful logic, not state itself. The example in the docs even mention a hook calleduseOnlineStatus
This is a patch we've made in our own app to solve Issue #669. I'm sure there are others out there who'd be keen on this functionality too so I'm starting an initial PR to see if there is any appetite for this or something else that'll achieve similar outcomes.
Test Plan