Skip to content

Commit

Permalink
Fix fonts not being initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
keupoz committed Jan 22, 2024
1 parent 0da1caa commit 3663c6b
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getFirstItem } from "@/utils/getFirstItem";
import { useLoader } from "@react-three/fiber";
import { Buffer } from "buffer";
import { create as createFont } from "fontkit";
import { FC, Suspense, useEffect } from "react";
import { FC, Suspense } from "react";
import { FileLoader } from "three";
import { AppContent } from "./AppContent";

Expand Down Expand Up @@ -56,31 +56,16 @@ const AppWrapper: FC = () => {
return createFont(Buffer.from(rawFont));
});

useEffect(() => {
useFontsStore.setState({ fonts });
}, [fonts]);
const font = getFirstItem(fonts);
const features = collectFeatures(font);

useEffect(() => {
const font = getFirstItem(fonts);
const features = collectFeatures(font);

useFontSettings.setState({
textFont: font,
markFont: font,
textFeatures: features,
markFeatures: features,
});

return () => {
useFontSettings.setState({
textFont: null,
markFont: null,
textFeatures: {},
markFeatures: {},
});
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useFontsStore.setState({ fonts });
useFontSettings.setState({
textFont: font,
markFont: font,
textFeatures: features,
markFeatures: features,
});

return <AppContent />;
};

0 comments on commit 3663c6b

Please sign in to comment.