Skip to content

Instantly share code, notes, and snippets.

View KristofferEriksson's full-sized avatar

Kristoffer Eriksson KristofferEriksson

View GitHub Profile
@KristofferEriksson
KristofferEriksson / useDeviceOrientation.ts
Created February 13, 2024 15:10
A React Typescript hook that utilizes the DeviceOrientation API to provide real-time orientation data of a device in 3D space
import { useCallback, useEffect, useState } from "react";
interface DeviceOrientationState {
alpha: number | null;
beta: number | null;
gamma: number | null;
absolute: boolean;
}
// Define an extended interface for DeviceOrientationEvent including requestPermission
@KristofferEriksson
KristofferEriksson / useNetwork.ts
Created February 13, 2024 22:04
A React Typescript hook to get real-time network insights
import { useEffect, useState } from "react";
interface NetworkInformation extends EventTarget {
downlink?: number;
effectiveType?: "slow-2g" | "2g" | "3g" | "4g";
rtt?: number;
saveData?: boolean;
onchange?: EventListener;
}