-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed React Invalid Hook Error by removing useFontObserver. Improved …
…readme, and default values.
- Loading branch information
1 parent
c9c1aaa
commit 51ba2e2
Showing
14 changed files
with
181 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = useFonts; | ||
require("core-js/modules/web.dom-collections.iterator.js"); | ||
require("core-js/modules/es.promise.js"); | ||
var _react = require("react"); | ||
function useFonts() { | ||
for (var _len = arguments.length, fontNames = new Array(_len), _key = 0; _key < _len; _key++) { | ||
fontNames[_key] = arguments[_key]; | ||
} | ||
const [isLoaded, setIsLoaded] = (0, _react.useState)(false); | ||
(0, _react.useEffect)(() => { | ||
// Inspired by https://stackoverflow.com/a/60138011 | ||
if (!document || !document.fonts) { | ||
// eslint-disable-next-line no-console | ||
console.warn('Browser does not support document.fonts API'); | ||
setIsLoaded(true); | ||
return; | ||
} | ||
Promise.all(fontNames.map(fontName => document.fonts.load("16px \"".concat(fontName, "\"")))).then(() => { | ||
setIsLoaded(true); | ||
}); | ||
}, [fontNames]); | ||
return isLoaded; | ||
} | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.