14
votes

I am trying to connect Redux mapStateToProps() and mapActionCreators() to Login Screen through Container and I am using React navigation.

After build my app the following error message appears:

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

I searched for a while but what I have gotten is that React.memo() helps us control when our components rerender but I don't use any code related to React.memo().

Login Screen: (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
    }
}

Login screen container: (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);

Top level navigation: (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:

"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"
},
4

4 Answers

14
votes

I solved it, it seems that React-Redux package depend on React 16.8.0 and uses React.memo() somehow so I downgraded React-Redux to v6.0.0

13
votes

Same as the solutions above but with instructions. Be sure to clear the Expo cache!

Downgrade your react-redux to version 6.0.1

npm install [email protected]

Clear the cache in Expo

expo r -c
2
votes

Downgrade your react-redux to v6.0.0 and start your expo project by expo r -c which resets the cache

1
votes

Can't comment yet, so adding this as an addition to Ahmed Saeed's response above. As of today, April 17, Hooks are not supported on Expo yet, read more here. From v.7.0.1 react-redux

connect now uses React.memo() internally, which returns a special object rather than a function.

And it's rewritten with Hooks. Downgrading react-redux to v.6.0.0 helps.