UNPKG

use-font-face-observer

Version:

React hook to detect if web fonts are available 🪝

3 lines (2 loc) 592 B
import{useState as r,useEffect as t}from"react";import o from"fontfaceobserver";function e(e,n,i){void 0===e&&(e=[]);var c=void 0===n?{}:n,s=c.testString,f=c.timeout,a=(void 0===i?{showErrors:!1}:i).showErrors,u=r(!1),l=u[0],d=u[1],h=JSON.stringify(e);return t(function(){var r=JSON.parse(h).map(function(r){return new o(r.family,{weight:r.weight,style:r.style,stretch:r.stretch}).load(s,f)});Promise.all(r).then(function(){return d(!0)}).catch(function(r){a&&console.error("An error occurred during font loading",r)})},[h,s,f,a]),l}export default e; //# sourceMappingURL=index.module.js.map