捆绑失败:SyntaxError意外令牌,预期为本地反应

时间:2018-08-06 11:07:26

标签: react-native react-native-tab-view

renderScene ={SceneMap({
'1':() =>  <FirstRoute {...this.state.data}/>,
'2':() =>  <SecondRoute {...this.state.data,...this.props.navigation}/>

这是完整的代码

render() {

  if(!this.state.loading){
      return (
        <View
          style={{
            flex: 1,
          }}>
          <StatusBar
             backgroundColor="mediumpurple"
             barStyle="light-content"/>
          <TabView
            style={styles.container}
            navigationState={this.state}
            renderScene ={SceneMap({
              '1':() =>  <FirstRoute {...this.state.data}/>,
              '2':() =>  <SecondRoute {...this.state.data, ...this.props.navigation}/>,
            })}
            renderHeader={this._renderHeader}
            onIndexChange={index => this.setState({ index })}
          />

        </View>
      );

  }else{
    return (
        <View style={styles.loadingContainer}>
          <ActivityIndicator size="large" color="#0000ff" />
        </View>
    );
  }
 }
}

1 个答案:

答案 0 :(得分:0)

{...a, ...b}不是javascript表达式,因此会引发意外令牌错误。

您可以使用以下之一:

  • <SecondRoute {...{...this.state.data,...this.props.navigation}} />
  • const mergedObjects = {...this.state.data,...this.props.navigation}

    <SecondRoute {...mergedObjects}/>

  • <SecondRoute {...this.state.data} {...this.props.navigation} />