Skip to content

Latest commit

 

History

History
63 lines (52 loc) · 1.03 KB

doc.md

File metadata and controls

63 lines (52 loc) · 1.03 KB

useNetwork

Vue hook that tracks connected hardware devices.

Browser environment is required

Returns:

{
  "online": true,
  "since": "2019-11-04T16:13:21.003Z",
  "downlink": 4.4,
  "downlinkMax": null,
  "effectiveType": "4g",
  "rtt": 200,
  "type": "wifi"
}

Usage

import { createComponent } from '@vue/composition-api'
import { useNetwork } from 'vuses'

const Demo = createComponent({
  setup() {
    const network = useNetwork()
    return { network }
  },
  render() {
    const { network } = this
    return <pre>{JSON.stringify(network, null, 2)}</pre>
  }
})

Reference

interface NetworkState {
  online?: boolean
  since?: Date
  downlink?: number
  downlinkMax?: number
  effectiveType?: string
  rtt?: number
  type?: string
}

const defaultState = {
  online: false,
  since: undefined,
  downlink: undefined,
  downlinkMax: undefined,
  effectiveType: undefined,
  rtt: undefined,
  type: undefined
}

function useNetwork(initialState: NetworkState = defaultState): NetworkState