Skip to content

Commit

Permalink
Merge pull request #4 from Renna-Labs/v1.1.3
Browse files Browse the repository at this point in the history
v1.1.3
  • Loading branch information
echoghi committed Feb 3, 2023
2 parents 3f552cc + 7eba5ec commit ed99dcc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rennalabs/hooks",
"version": "1.1.2",
"version": "1.1.3",
"description": "A library of useful hooks.",
"main": "dist/index.js",
"typings": "types/index.d.ts",
Expand Down
11 changes: 10 additions & 1 deletion src/useNetworkStatus/useNetworkStatus.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { useState, useEffect } from 'react';
import { isClient } from '../utils';

interface NetworkStatus {
isOnline: boolean;
offlineAt: Date | undefined;
}

function getInitialValue(): boolean {
if (isClient && typeof navigator !== 'undefined') {
return navigator.onLine;
}

return false;
}

export const useNetworkStatus = (): NetworkStatus => {
const [status, setStatus] = useState<boolean>(navigator.onLine);
const [status, setStatus] = useState<boolean>(getInitialValue());
const [offlineAt, setOfflineAt] = useState<Date | undefined>(undefined);

useEffect(() => {
Expand Down
7 changes: 0 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ export const isClient: boolean = typeof window === 'object';

/**
* Clamps a given value within a specified range.
*
* @param {number} value - The value to be clamped.
* @param {number} min - The minimum value of the range.
* @param {number} max - The maximum value of the range.
*
* @returns {number} The clamped value.
*/

export function clamp(value: number, min: number, max: number) {
return Math.min(Math.max(value, min), max);
}
Expand Down

0 comments on commit ed99dcc

Please sign in to comment.