Skip to content

Commit

Permalink
Refactor hooks to named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisllontop committed Dec 5, 2024
1 parent 6d19884 commit 6cd52ba
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/hooks/src/hooks/useArray.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";

export default function useArray<T>(initialArray: T[]) {
export const useArray = <T>(initialArray: T[]) => {
const [array, setArray] = useState<T[]>(initialArray);

const push = (element: T) => {
Expand Down Expand Up @@ -39,4 +39,4 @@ export default function useArray<T>(initialArray: T[]) {
remove,
clear,
};
}
};
6 changes: 3 additions & 3 deletions packages/hooks/src/hooks/useEventListener.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useEffect, useRef } from "react";

export default function useEventListener(
export const useEventListener = (
eventName: string,
callback: EventListener,
element:
| HTMLElement
| (Window & typeof globalThis)
| Document
| null = window,
) {
) => {
const callbackRef = useRef<EventListener>(callback);

useEffect(() => {
Expand All @@ -28,4 +28,4 @@ export default function useEventListener(
element.removeEventListener(eventName, eventListener);
};
}, [eventName, element]);
}
};
4 changes: 2 additions & 2 deletions packages/hooks/src/hooks/useGeolocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface Payload {
lng: number;
}

export function useGeolocation(defaultPosition: Payload | null = null) {
export const useGeolocation = (defaultPosition: Payload | null = null) => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [position, setPosition] = useState<Payload | null>(defaultPosition);
const [error, setError] = useState<string | null>(null);
Expand Down Expand Up @@ -33,4 +33,4 @@ export function useGeolocation(defaultPosition: Payload | null = null) {
}

return { isLoading, position, error, getPosition };
}
};
2 changes: 1 addition & 1 deletion packages/hooks/src/hooks/useOnScreen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type RefObject, useEffect, useState } from "react";

export default function useOnScreen(
export function useOnScreen(
ref: RefObject<Element>,
rootMargin = "0px",
): boolean {
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/hooks/usePrevious.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRef } from "react";

export default function usePrevious<T>(value: T): T | undefined {
export const usePrevious = <T>(value: T): T | undefined => {
const currentRef = useRef<T>(value);
const previousRef = useRef<T>();

Expand All @@ -10,4 +10,4 @@ export default function usePrevious<T>(value: T): T | undefined {
}

return previousRef.current;
}
};

0 comments on commit 6cd52ba

Please sign in to comment.