From 6cd52ba2d44dfc586959b783b23b4d2fe0c6d128 Mon Sep 17 00:00:00 2001 From: Christian Llontop Date: Wed, 4 Dec 2024 23:00:27 -0500 Subject: [PATCH] Refactor hooks to named exports --- packages/hooks/src/hooks/useArray.ts | 4 ++-- packages/hooks/src/hooks/useEventListener.ts | 6 +++--- packages/hooks/src/hooks/useGeolocation.ts | 4 ++-- packages/hooks/src/hooks/useOnScreen.ts | 2 +- packages/hooks/src/hooks/usePrevious.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/hooks/src/hooks/useArray.ts b/packages/hooks/src/hooks/useArray.ts index 02ef8d4..3310ae3 100644 --- a/packages/hooks/src/hooks/useArray.ts +++ b/packages/hooks/src/hooks/useArray.ts @@ -1,6 +1,6 @@ import { useState } from "react"; -export default function useArray(initialArray: T[]) { +export const useArray = (initialArray: T[]) => { const [array, setArray] = useState(initialArray); const push = (element: T) => { @@ -39,4 +39,4 @@ export default function useArray(initialArray: T[]) { remove, clear, }; -} +}; diff --git a/packages/hooks/src/hooks/useEventListener.ts b/packages/hooks/src/hooks/useEventListener.ts index 9014922..281ebf3 100644 --- a/packages/hooks/src/hooks/useEventListener.ts +++ b/packages/hooks/src/hooks/useEventListener.ts @@ -1,6 +1,6 @@ import { useEffect, useRef } from "react"; -export default function useEventListener( +export const useEventListener = ( eventName: string, callback: EventListener, element: @@ -8,7 +8,7 @@ export default function useEventListener( | (Window & typeof globalThis) | Document | null = window, -) { +) => { const callbackRef = useRef(callback); useEffect(() => { @@ -28,4 +28,4 @@ export default function useEventListener( element.removeEventListener(eventName, eventListener); }; }, [eventName, element]); -} +}; diff --git a/packages/hooks/src/hooks/useGeolocation.ts b/packages/hooks/src/hooks/useGeolocation.ts index bb44149..4cd9136 100644 --- a/packages/hooks/src/hooks/useGeolocation.ts +++ b/packages/hooks/src/hooks/useGeolocation.ts @@ -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(false); const [position, setPosition] = useState(defaultPosition); const [error, setError] = useState(null); @@ -33,4 +33,4 @@ export function useGeolocation(defaultPosition: Payload | null = null) { } return { isLoading, position, error, getPosition }; -} +}; diff --git a/packages/hooks/src/hooks/useOnScreen.ts b/packages/hooks/src/hooks/useOnScreen.ts index 818b549..bb03a64 100644 --- a/packages/hooks/src/hooks/useOnScreen.ts +++ b/packages/hooks/src/hooks/useOnScreen.ts @@ -1,6 +1,6 @@ import { type RefObject, useEffect, useState } from "react"; -export default function useOnScreen( +export function useOnScreen( ref: RefObject, rootMargin = "0px", ): boolean { diff --git a/packages/hooks/src/hooks/usePrevious.ts b/packages/hooks/src/hooks/usePrevious.ts index 73ff94a..8b14a2b 100644 --- a/packages/hooks/src/hooks/usePrevious.ts +++ b/packages/hooks/src/hooks/usePrevious.ts @@ -1,6 +1,6 @@ import { useRef } from "react"; -export default function usePrevious(value: T): T | undefined { +export const usePrevious = (value: T): T | undefined => { const currentRef = useRef(value); const previousRef = useRef(); @@ -10,4 +10,4 @@ export default function usePrevious(value: T): T | undefined { } return previousRef.current; -} +};