use-font-face-observer
Version:
React hook to detect if web fonts are available 🪝
3 lines (2 loc) • 499 B
JavaScript
import{useState as r,useEffect as t}from"react";import o from"fontfaceobserver";function e(e=[],{testString:s,timeout:n}={},{showErrors:i}={showErrors:!1}){const[c,a]=r(!1),f=JSON.stringify(e);return t(()=>{const r=JSON.parse(f).map(({family:r,weight:t,style:e,stretch:i})=>new o(r,{weight:t,style:e,stretch:i}).load(s,n));Promise.all(r).then(()=>a(!0)).catch(r=>{i&&console.error("An error occurred during font loading",r)})},[f,s,n,i]),c}export default e;
//# sourceMappingURL=index.modern.js.map