react-detect-offline
react-detect-offline copied to clipboard
Use React context with provider/consumer to pass status
I am using the Online and Offline components in a couple of places within my application and noticed that the application is hitting the polling url every 5 seconds about 3 times, which shows that each Online/Offline component checks separately for the connection's status.
I propose creating a Provider which could be used to wrap the application's root component and just use a Consumer anywhere where the connection status is needed.
It would look something like:
<Provider {...config}>
<App />
</Provider>
<Consumer>
{({ online }) => (
<div>
{`${online}`}
</div>
)}
</Consumer>
I can create a PR to implement it if it's OK.
What do you think ?
I love the idea of having one provider! Definitely put up the PR and I can take a look at it. Thank you!
Hopefully something we can do in v3