Hi!
I’m making a template for apps and need to move all additional (custom) fonts to a separate module. For now, I did as described in docs:
App.js
import {
useFonts,
Scheherazade_400Regular
} from '@expo-google-fonts/scheherazade'
Ideally I want to make in config.js
:
export const additionalFonts = {
Scheherazade_400Regular: '@expo-google-fonts/scheherazade',
Inter_100Thin: '@expo-google-fonts/inter',
Inter_300Light: '@expo-google-fonts/inter'
}
And then import them at once:
import {additionalFonts} from './config.js'
I tried this code, but executing hook in async function causes an error:
import React, { useState } from 'react'
import AppLoading from 'expo-app-loading'
import {
useFonts,
Scheherazade_400Regular
} from '@expo-google-fonts/scheherazade'
// import {useFonts} from '@expo-google-fonts/inter'
import { Provider as ReduxProvider } from 'react-redux'
import { ThemeProvider } from 'react-native-elements'
import store from './src/store/rootReducer'
import RootNavigation from './src/navigation/RootNavigation'
export default function App() {
// const [fontLoaded] = useFonts({ Scheherazade_400Regular })
const [fontsLoaded, setFontsLoaded] = useState(false)
const loadFonts = async () => {
const modules = await Promise.all([
import('@expo-google-fonts/scheherazade'),
import('@expo-google-fonts/inter')
])
const fonts = modules.reduce((prevItem, currentItem) => {
return { ...prevItem, ...currentItem }
}, {})
const { useFonts, Scheherazade_400Regular } = fonts
console.log('fonts', fonts)
// console.log('useFonts', useFonts({ Scheherazade_400Regular }))
// useFonts({ Scheherazade_400Regular })
setFontsLoaded(true)
}
loadFonts()
return fontsLoaded ? (
<ReduxProvider store={store}>
<ThemeProvider>
<RootNavigation />
</ThemeProvider>
</ReduxProvider>
) : (
<AppLoading />
)
}
Please, if someone has ides, share with me.