Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
useEffect( () => {
const subscription = DataStore.observe(Post).subscribe(msg => {
console.log(msg.model, msg.opType, msg.element);
listPosts(setPosts);
});
const handleConnectionChange = () => {
const condition = navigator.onLine ? 'online' : 'offline';
console.log(condition);
if (condition === 'online') { listPosts(setPosts); }
}
window.addEventListener('online', handleConnectionChange);
window.addEventListener('offline', handleConnectionChange);
return () => subscription.unsubscribe();
}, []);