Ashutoshdikshit07 / paytm

Learning
0 stars 0 forks source link

New Function - Add a funtionality to tell if the user is online or offline. #12

Open Ashutoshdikshit07 opened 7 months ago

Ashutoshdikshit07 commented 7 months ago

Browser functionality hooks. Create a custom hook to tell if they are online or not.

Ashutoshdikshit07 commented 7 months ago

Hint to create a isOnline hook - `function useIsOnline(){ const [isOnline, setIsOnline] = useState(window.navigator.onLine)

useEffect(()=>{ window.addEventListener("online",()=>{ setIsOnline(true) })

window.addEventListener("offline",()=>{
  setIsOnline(false)
})

},[])

return isOnline }

function App(){

const isOnline = useIsOnline()

if(isOnline){ return "you are online yay!!" } else{ return "you are offline please connect to the internet" } `