我在React Native中使用“ Super(props)”时遇到错误

时间:2020-09-19 08:34:39

标签: javascript react-native

当我按照本教程https://www.youtube.com/watch?v=5Fkx87SMoJc制作应用时。我遇到一个错误;

enter image description here

我也看到了super(props)上的一行;在VS代码中;

enter image description here

这是我的代码,因为我仍然是初学者,请通过更正我的代码来解决问题。

import React, { Component } from 'react';
import { AppRegistry } from 'react-native';
import Splash from './components/splash';
import Home from './components/index';

class Main extends Component {
  constructor(props) {
    super(props);
    this.state = { CurrentScreen: 'Splash' };
    console.log('Moving to next screen...');
    setTimeout(()=>{
      console.log('Done!');
      this.setState({ CurrentScreen: 'Home' });
    }, 3000)
  }
  render() {
    const { CurrentScreen } = this.state
    let mainScreen = CurrentScreen === 'Splash' ? <Splash /> : <Home />
    return mainScreen
  }
}

AppRegistry.registerComponent('App', () => Splash)

非常感谢您。

0 个答案:

没有答案