Struggling with 'useFonts' being read-only and unable to assign
In my Expo project using React Native (TypeScript), I encounter the issue of trying to import a .ttf font file.
My attempt was to create a custom hook called "useFont" to pre-load all fonts before launching the application. More details can be found here.
Initially, this was my approach:
import * as Font from "expo-font";
export default useFonts = async () =>
await Font.loadAsync({
'LeagueSpartan': require('../assets/fonts/LeagueSpartan.ttf'),
});
However, the error Cannot find name 'useFonts'
kept coming up.
So, I made another attempt like so:
import * as Font from "expo-font";
export default Font.useFonts = async () =>
await Font.loadAsync({
'LeagueSpartan': require('../assets/fonts/LeagueSpartan.ttf'),
});
But now, I am faced with
Cannot assign to 'useFonts' because it is a read-only property
.
It seems like neither option is working for me. Any guidance would be greatly appreciated!