From 2957ec5e71994eb5ec5148eec2a10f72dceefa9e Mon Sep 17 00:00:00 2001 From: Arnei Date: Tue, 28 May 2024 15:44:44 +0200 Subject: [PATCH] Remove extra util file It is not necessary. --- src/confirmationModal.tsx | 2 +- src/index.tsx | 1 - src/util.tsx | 11 +++++++++++ src/utilFunc.ts | 12 ------------ 4 files changed, 12 insertions(+), 14 deletions(-) delete mode 100644 src/utilFunc.ts diff --git a/src/confirmationModal.tsx b/src/confirmationModal.tsx index ccd9244..4a7083e 100644 --- a/src/confirmationModal.tsx +++ b/src/confirmationModal.tsx @@ -8,7 +8,7 @@ import { useImperativeHandle, } from "react"; import { ModalProps, ModalHandle, Modal, Spinner, Button, boxError } from "."; -import { currentRef } from "./utilFunc"; +import { currentRef } from "./util"; type ConfirmationModalProps = Omit & { diff --git a/src/index.tsx b/src/index.tsx index 857dc94..8a10afc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -11,7 +11,6 @@ export * from "./floating"; export * from "./header"; export * from "./spinner"; export * from "./util"; -export * from "./utilFunc"; export * from "./modal"; export * from "./styledButton"; diff --git a/src/util.tsx b/src/util.tsx index df992ab..0e9e2fe 100644 --- a/src/util.tsx +++ b/src/util.tsx @@ -1,4 +1,5 @@ import { MutableRefObject, useEffect } from "react"; +import { bug } from "./err"; /** * A switch-case-like expression with exhaustiveness check (or fallback value). @@ -69,3 +70,13 @@ export const useOnOutsideClick = ( return () => document.removeEventListener("mousedown", handler); }); }; + +/** + * Accesses the current value of a ref, signaling an error when it is unbound. + * Note: **Don't** use this if you expect the ref to be unbound temporarily. + * This is mainly for accessing refs in event handlers for elements + * that are guaranteed to be alive as long as the ref itself. + */ +export const currentRef = (ref: React.RefObject): T => ( + ref.current ?? bug("ref unexpectedly unbound") +); diff --git a/src/utilFunc.ts b/src/utilFunc.ts deleted file mode 100644 index caba4a5..0000000 --- a/src/utilFunc.ts +++ /dev/null @@ -1,12 +0,0 @@ -import React from "react"; -import { bug } from "."; - -/** - * Accesses the current value of a ref, signaling an error when it is unbound. - * Note: **Don't** use this if you expect the ref to be unbound temporarily. - * This is mainly for accessing refs in event handlers for elements - * that are guaranteed to be alive as long as the ref itself. - */ -export const currentRef = (ref: React.RefObject): T => ( - ref.current ?? bug("ref unexpectedly unbound") -);