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

Answer by Oleg for React Native importing fonts with async componentDidMount() expected =>

$
0
0

If you want to use Functional Component with hooks, try like this:

add to imports:

 import { useState, useEffect } from 'react';

and

const Home = () => {

  const [fontLoaded, setFontLoaded] = useState(false);
  useEffect(async() => {
   await Font.loadAsync({
       Pacifico: require('../assets/pacifico/Pacifico.ttf'),
    });
    setFontLoaded(true);
  }, []);

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

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>