use-network-state3
v1.0.1
Published
Monitor and adapt to network conditions seamlessly with useNetworkState.
Downloads
6
Readme
use-network-state3
Monitor and adapt to network conditions seamlessly with useNetworkState.
Installation
To install the package, use npm:
pnpm add use-network-state3
yarn install use-network-state3
npm install use-network-state3
Usage
import React from "react";
import { useNetworkState } from "use-network-state3";
const NetworkStatus = () => {
const networkState = useNetworkState();
return (
<div>
<p>Online: {networkState.online ? "Yes" : "No"}</p>
{networkState.since && (
<p>Since: {networkState.since.toLocaleTimeString()}</p>
)}
{networkState.downlink && <p>Downlink: {networkState.downlink} Mb/s</p>}
{networkState.effectiveType && (
<p>Effective Connection Type: {networkState.effectiveType}</p>
)}
{networkState.type && <p>Connection Type: {networkState.type}</p>}
<p>Data Saver Mode: {networkState.saveData ? "Enabled" : "Disabled"}</p>
</div>
);
};
export default NetworkStatus;
tsup
Bundle your TypeScript library with no config, powered by esbuild.
https://tsup.egoist.dev/
How to use this
- install dependencies
# pnpm
$ pnpm install
# yarn
$ yarn install
# npm
$ npm install
- Add your code to
src
- Add export statement to
src/index.ts
- Test build command to build
src
. Once the command works properly, you will seedist
folder.
# pnpm
$ pnpm run build
# yarn
$ yarn run build
# npm
$ npm run build
- Publish your package
$ npm publish
test package
https://www.npmjs.com/package/use-network-state3