From 241731cad63851222cd63dbca2b5cd4ff7449641 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 9 Feb 2022 13:50:26 +0100 Subject: [PATCH] Add `useBluelibInBody` hook --- src/hooks/useBluelibInBody.tsx | 16 ++++++++++++++++ src/index.ts | 1 + 2 files changed, 17 insertions(+) create mode 100644 src/hooks/useBluelibInBody.tsx diff --git a/src/hooks/useBluelibInBody.tsx b/src/hooks/useBluelibInBody.tsx new file mode 100644 index 0000000..e7f2c26 --- /dev/null +++ b/src/hooks/useBluelibInBody.tsx @@ -0,0 +1,16 @@ +import { useRef, useEffect } from "react" +import { useBluelib } from "./useBluelib" + +export function useBluelibInBody(theme) { + const ref = useRef(null) + useEffect( + () => { + ref.current = document.body as HTMLBodyElement + }, + [ref] + ) + + useBluelib(ref, { + theme, + }) +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 56de9f9..915dcc9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,3 +60,4 @@ export {Bluelib as default} from "./components/Bluelib" export {usePromise} from "./hooks/usePromise" export {useFormState} from "./hooks/useFormState" export {useBluelib} from "./hooks/useBluelib" +export {useBluelibInBody} from "./hooks/useBluelibInBody"