gpt4 book ai didi

reactjs - 如何修复 '_react["default"].memo 不是函数。(在 React Native 中的 '_react["default"].memo(connectFunction)' 错误?

转载 作者:行者123 更新时间:2023-12-03 13:16:15 25 4
gpt4 key购买 nike

我正在尝试通过容器将 Redux mapStateToProps() 和 mapActionCreators() 连接到登录屏幕,并且我正在使用 React 导航。

构建我的应用程序后,出现以下错误消息:

_react["default"].memo is not a function. (In '_react["defaults"].memo(connectFunction)', '_react["defaults"].memo' is undefined.

我搜索了一段时间,但我得到的是 React.memo() 帮助我们控制组件何时重新渲染,但我没有使用与 React.memo() 相关的任何代码。

登录屏幕:(screens/LoginScreen/index.js)

import React from 'react';
import {Dimensions, View} from 'react-native';

//Get width of mobile screen
var width = Dimensions.get("window").width;
var height = Dimensions.get("window").height;

export default class LoginScreen extends React.Component {
constructor(props){
super(props);
this.state = {

}
}

render() {
return (
<View style={styles.container}>
<Text>Log In page</Text>
</View>
);
}
}

LoginScreen.defaultProps = {
}

const styles = {
container: {
flex: 1
}
}

登录屏幕容器:(containers/LoginContainer/index.js)

import {connect} from "react-redux";
import LoginScreen from "../../screens/LoginScreen";

const mapStateToProps = (state) =>({

});


const mapActionCreators = {

};
export default connect(mapStateToProps, mapActionCreators)(LoginScreen);

顶级导航:(navigations/TopLevelSwitchNav.js)

import {createSwitchNavigation, createAppContainer} from 'react-navigation';
import LoginScreen from '../containers/LoginContainer';
import MainTabNav from './MainTabNav';


const TopLevelSwitchNav = createSwitchNavigation({
Login: {
screen: LoginScreen,
navigationOptions: {
header: null
}
},
MainTab: {
screen: MainTabNav,
navigationOptions: {
header: null
}
}
},
{
initialRouteName: Login,
navigationOptions: { header: null }
});

export default createAppContainer(TopLevelSwitchNav);

依赖关系:

"dependencies": {
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-navigation": "^3.8.1",
"react-redux": "^7.0.2",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-persist": "^5.10.0",
"redux-persist-transform-filter": "^0.0.18",
"redux-thunk": "^2.3.0"
},

最佳答案

我解决了这个问题,看来React-Redux包依赖于React 16.8.0并以某种方式使用React.memo(),所以我将React-Redux降级到v6.0.0

关于reactjs - 如何修复 '_react["default"].memo 不是函数。(在 React Native 中的 '_react["default"].memo(connectFunction)' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55691069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com