React Native(Expo)如何设置默认字体(或者是全局字体)?

React Native(Expo)如何设置默认字体(或者是全局字体)?
如果自定义一个Text组件, 可能要异步加载,如下:

  componentWillMount = async () => {
    await Font.loadAsync({
      'a: require('../fonts/aaa.ttf'),
      'b': require('../fonts/bbb.ttf')
    });
    this.setState({ fontLoaded: true });
  };

那么可能会出现如下错误:

Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
阅读 3.6k
1 个回答

这个报错信息是因为你在componentWillMount中执行setState的原因
你改成componentDidMount就可以了

推荐问题