Quantcast
Channel: React Native importing fonts with async componentDidMount() expected => - Stack Overflow
Viewing all articles
Browse latest Browse all 2

React Native importing fonts with async componentDidMount() expected =>

0
0

I am trying to import a font for a title of a project, and I am loading the font as such:

import * as Font from 'expo-font'


const Home = () => {

return(
this.state = {
    fontLoaded: false
  }
   async componentDidMount(){
      await Font.loadAsync({
        'Pacifico': require('../assets/pacifico/Pacifico.ttf'),
      }).then(() => {
      this.setState({fontLoaded: true})
    })

<View style={{marginTop:30, alignItems:'center'}}>
    {this.state.fontLoaded ? (<Text>Loading...</Text>): (
    <Text style={{fontSize:40, fontFamily:'Pacifico'}}>Book Lover</Text>
    )}
    </View>
)}

however when I am compiling the project I get an error saying Unexpected token, expected "=>" and it points to the async componentDidMount(){ line

is there anything I can fix?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images