【问题标题】:How to fix '_react["default"].memo is not a function. (In '_react["default"].memo(connectFunction)' error in React native?如何修复 '_react["default"].memo 不是函数。 (在 React native 中的 '_react["default"].memo(connectFunction)' 错误?
【发布时间】:2019-09-05 13:07:40
【问题描述】:

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

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

_react["default"].memo 不是函数。 (在 '_react["defaults"].memo(connectFunction)' 中,'_react["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);

顶级导航:(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"
},

【问题讨论】:

    标签: reactjs react-native redux react-redux


    【解决方案1】:

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

    【讨论】:

    • 1.转到您的 package.json 文件并将“react-redux”版本更改为“6.0.0” 2. 运行 npm install
    【解决方案2】:

    与上述解决方案相同,但带有说明。请务必清除 Expo 缓存!

    将你的 react-redux 降级到 6.0.1 版

    npm install react-redux@6.0.1
    

    在 Expo 中清除缓存

    expo r -c
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        尚不能发表评论,因此将其添加到 Ahmed Saeed 的回复 above 中。 截至今天,4 月 17 日,Expo 尚不支持 Hooks,阅读更多 here。从 v.7.0.1 react-redux

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

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

        【讨论】:

          猜你喜欢
          • 2018-01-08
          • 1970-01-01
          • 2017-07-27
          • 1970-01-01
          • 2019-03-08
          • 1970-01-01
          • 2023-01-28
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多