npm

@solid-primitives/connectivity
TypeScript icon, indicating that this package has built-in type declarations

0.3.20 • Public • Published

Solid Primitives Connectivity

@solid-primitives/connectivity

turborepo size version stage

A navigator.onLine signal that tells you when the browser thinks you're online. Connectivity is determined by your browser, which is a best-effort process.

Installation

npm install @solid-primitives/connectivity
# or
yarn add @solid-primitives/connectivity

makeConnectivityListener

Attaches event listeners and fires callback whenever window.onLine changes.

import { makeConnectivityListener } from "@solid-primitives/connectivity";

const clear = makeConnectivityListener(isOnline => {
  console.log(isOnline); // T: booelan
});
// remove event listeners (happens also on cleanup)
clear();

Definition

function makeConnectivityListener(callback: (isOnline: boolean) => void): VoidFunction;

createConnectivitySignal

A signal representing the browser's interpretation of whether it is on- or offline.

import { createConnectivitySignal } from "@solid-primitives/connectivity";

const isOnline = createConnectivitySignal();
isOnline(); // T: boolean

useConnectivitySignal

This primitive provides a singleton root variant that will reuse event listeners and signals across dependents.

It's behavior is the same as createConnectivitySignal.

import { useConnectivitySignal } from "@solid-primitives/connectivity";

const isOnline = useConnectivitySignal();
isOnline(); // T: boolean

Definition

function createConnectivitySignal(): Accessor<boolean>;

Demo

https://codesandbox.io/s/solid-primitives-connectivity-demo-2m76q?file=/index.tsx

Changelog

See CHANGELOG.md

Package Sidebar

Install

npm i @solid-primitives/connectivity

Weekly Downloads

1,198

Version

0.3.20

License

MIT

Unpacked Size

11.7 kB

Total Files

8

Last publish

Collaborators

  • thetarnav.
  • lexlohr
  • davedbase