Created
May 3, 2018 15:02
-
-
Save kulor/3e4d8744fb94f17314538bc6067ff57f to your computer and use it in GitHub Desktop.
Example Redux Offline config with network detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const reduxOfflineConfig = { | |
..., | |
detectNetwork: callback => { | |
setInterval(async () => { | |
try { | |
await fetch('yourbackend.com/ping', { method: 'HEAD' }) | |
callback({ | |
online: true | |
}) | |
} catch(e) { | |
callback({ | |
online: false | |
}) | |
} | |
}, 2000) | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment