React Native:为何在AppRegistry.registerComponent()中使用回调函数;

时间:2018-11-02 03:39:12

标签: react-native

我想了解下面代码的最后一行:

'use strict';
import React, { Component } from 'react';
import { Text, AppRegistry } from 'react-native';

export default class App extends Component {
  render() {
    return (
      <Text>Test</Text>
    );
  }
}

AppRegistry.registerComponent('TestApp', () => App);

据我了解,如果我通过App(),那将立即调用App。而如果我通过() => App,则此回调函数将返回App。

1)我不明白是什么使() => App成为回调函数。我相信如果我说App()会立即调用一个函数,但是这种写() => App的方式是否总是回调函数?

2)我也想了解为什么在AppRegistry.registerComponent();中使用回调函数是一个好习惯。立即退回App组件为什么不好?后台发生了什么事? React Native还没有准备好吗?如果我使用回调函数,它将在什么时候被调用以及将要调用什么?

0 个答案:

没有答案