如何修复'_react [“default”]。备忘录不是一个功能。 (在'_react [“default”]。在React native中的memo(connectFunction)'错误?

问题描述 投票:8回答:4

我试图通过Container将Redux mapStateToProps()和mapActionCreators()连接到登录屏幕,我正在使用React导航。

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

_react [“default”]。备忘录不是一个功能。 (在'_react [“defaults”]。memo(connectFunction)','_ last [“defaults”]。memo'未定义。

我搜索了一段时间,但我得到的是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);

顶级导航:(导航/顶级切换Nav.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"
},
reactjs react-native redux react-redux expo
4个回答
13
投票

我解决了它,似乎React-Redux包依赖于React 16.8.0并以某种方式使用React.memo()所以我将React-Redux降级为v6.0.0


11
投票

与上述解决方案相同,但有说明。务必清除世博会缓存!

将react-redux降级到6.0.1版

npm install [email protected]

清除世博会的缓存

expo r -c

1
投票

无法发表评论,因此将此添加为Ahmed Saeed的回复above。截至今天,4月17日,Hooks尚未获得世博会的支持,请阅读更多here。从v.7.0.1 react-redux

connect现在在内部使用React.memo(),它返回一个特殊的对象而不是一个函数。

它是带钩的rewritten。将react-redux降级至v.6.0.0会有所帮助。


1
投票

将您的react-redux降级到v6.0.0并通过expo r -c启动您的expo项目,重置缓存

© www.soinside.com 2019 - 2024. All rights reserved.