React Native Redux - 对象不是构造函数(评估'new ctor(props context)')

jam*_*phy 14 react-native react-redux

这是一个尝试使用 Redux 的非常简单的页面……请参阅下面的代码。

但是我收到错误 object is not a constructor (evaluating 'new ctor(props context)')

import React, {Component} from 'react';
import {Text, View} from 'react-native';
import {connect} from 'react-redux';

const mapStateToProps = state => ({
  userId: state.auth.userId,
});

class Message extends Component {
  render() {
    return (
      <View>
        <Text>Text here</Text>
      </View>
    );
  }
}

export default connect(
  mapStateToProps,
  null,
)(Message);
Run Code Online (Sandbox Code Playgroud)

小智 31

重置缓存对我有用:

react-native start --reset-cache
Run Code Online (Sandbox Code Playgroud)

其他的解决办法是使用createSwitchNavigator,而不是createStackNavigator在你的导航器容器。

  • 超级有趣..今天我在将一个简单的类组件连接到 Redux 后遇到了这个错误,并且疯狂地试图找出我做错了什么。在终端中简单地重新启动expo服务器即可解决。谢谢! (4认同)
  • “纱线缓存清理”对我来说很有效。世博会需要一些时间来重新构建该应用程序。 (3认同)