Compare commits
2 Commits
dde81e6d61
...
66c729a0ba
| Author | SHA1 | Date |
|---|---|---|
|
|
66c729a0ba | 5 years ago |
|
|
d5e966e5ef | 5 years ago |
2 changed files with 49 additions and 5 deletions
@ -0,0 +1,42 @@ |
|||||
|
import React, { useState, useEffect } from "react"; |
||||
|
|
||||
|
function OfflineStatus(props) { |
||||
|
const [isOnline, setOnlineStatus] = useState(true); |
||||
|
|
||||
|
useEffect(() => { |
||||
|
const setFromEvent = function (event) { |
||||
|
if (event.type === "online") { |
||||
|
setOnlineStatus(true); |
||||
|
} else if (event.type === "offline") { |
||||
|
setOnlineStatus(false); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
window.addEventListener("online", setFromEvent); |
||||
|
window.addEventListener("offline", setFromEvent); |
||||
|
|
||||
|
return () => { |
||||
|
window.removeEventListener("online", setFromEvent); |
||||
|
window.removeEventListener("offline", setFromEvent); |
||||
|
}; |
||||
|
}); |
||||
|
|
||||
|
return !isOnline ? ( |
||||
|
<> |
||||
|
<h5 className="pwa-warning"> |
||||
|
Estás sin internet. <br /> Sus datos se sincronizaran cuando vuelva la |
||||
|
conexión. |
||||
|
</h5> |
||||
|
<style jsx>{` |
||||
|
.pwa-warning { |
||||
|
background-color: orange; |
||||
|
color: black; |
||||
|
text-align: center; |
||||
|
padding: 10px; |
||||
|
} |
||||
|
`}</style>
|
||||
|
</> |
||||
|
) : null; |
||||
|
} |
||||
|
|
||||
|
export default OfflineStatus; |
||||
@ -1,11 +1,13 @@ |
|||||
import React from 'react'; |
import React from "react"; |
||||
import ReactDOM from 'react-dom'; |
import ReactDOM from "react-dom"; |
||||
import './index.css'; |
import "./index.css"; |
||||
import App from './App'; |
import App from "./App"; |
||||
|
import OfflineStatus from "./OfflineStatus"; |
||||
|
|
||||
ReactDOM.render( |
ReactDOM.render( |
||||
<React.StrictMode> |
<React.StrictMode> |
||||
|
<OfflineStatus /> |
||||
<App /> |
<App /> |
||||
</React.StrictMode>, |
</React.StrictMode>, |
||||
document.getElementById('root') |
document.getElementById("root") |
||||
); |
); |
||||
|
|||||
Loading…
Reference in new issue