mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-15 01:01:43 +10:00
🚀 release v3.0.0
This commit is contained in:
29
client/wrappers/FontWrapper.tsx
Normal file
29
client/wrappers/FontWrapper.tsx
Normal file
@ -0,0 +1,29 @@
|
||||
import get from 'lodash/get';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
|
||||
import { useAppSelector } from '@/store/hooks';
|
||||
|
||||
const FontWrapper: React.FC = ({ children }) => {
|
||||
const typography = useAppSelector((state) => get(state.resume, 'metadata.typography'));
|
||||
|
||||
const loadFonts = useCallback(async () => {
|
||||
const WebFont = (await import('webfontloader')).default;
|
||||
const families = Object.values<string[]>(typography.family).reduce(
|
||||
(acc, family) => [...acc, `${family}:400,600,700`],
|
||||
[]
|
||||
);
|
||||
|
||||
WebFont.load({ google: { families } });
|
||||
}, [typography]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined' && !isEmpty(typography)) {
|
||||
loadFonts();
|
||||
}
|
||||
}, [typography, loadFonts]);
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
export default FontWrapper;
|
||||
Reference in New Issue
Block a user