Skip to content

Commit 32245a0

Browse files
author
Francis Champagne
committed
Add a class for "all loaded"
1 parent 9e1b1a6 commit 32245a0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

hooks/useFontListener.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useRef, useState } from "react"
1+
import { useEffect, useMemo, useRef, useState } from "react"
22
import { kebabCase } from "../utils"
33

44
declare var document: { fonts: any }
@@ -33,6 +33,7 @@ export const useFontListener: fontListenerHook = ({
3333
() => (scope === "html" ? "documentElement" : "body"),
3434
[scope]
3535
)
36+
const targetElementClassList = document[targetElement].classList
3637

3738
const apiAvailable = "fonts" in document
3839

@@ -67,7 +68,7 @@ export const useFontListener: fontListenerHook = ({
6768
}
6869

6970
function addClassName(fontName) {
70-
document[targetElement].classList.add(`wf-${kebabCase(fontName)}--loaded`)
71+
targetElementClassList.add(`wf-${kebabCase(fontName)}--loaded`)
7172
}
7273

7374
function isFontLoaded() {
@@ -103,6 +104,7 @@ export const useFontListener: fontListenerHook = ({
103104

104105
if (allFontsLoaded) {
105106
setHasLoaded(true)
107+
targetElementClassList.add(`wf-all--loaded`)
106108
}
107109
}
108110
}

0 commit comments

Comments
 (0)