Soutou
Soutou

Reputation: 73

error when using connect (function of the react-redux library)

I have a component class that I am using react-redux to connect the redux store, but I am getting an error when I try to pass the component into the connect function.

_react.default.memo is not a function. (In '_react.default.memo(ConnectFunction), '_react.default.memo' is undefined)

wrapWithConnect C:\Users\SESA506797XmobileApp Gatherman\node modul es react-redux\lib\components connectAdvanced.js: 339:45

I enclose an image of the generated errerur

Here is the content of the class in which connect was called

FilmDetail

import React from 'react'
import { StyleSheet, View, ActivityIndicator, ScrollView, Text, Image } 
from 'react-native'
import { getFilmDetailFromApi, getImageFromApi } from '../API/TMDBApi'
import { connect } from 'react-redux'

class FilmDetail extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      film: undefined,
    }
  }
  componentDidMount() {
    getFilmDetailFromApi(this.props.navigation.state.params.idFilm).then(data => {
      this.setState({
        film:data,
        isLoading: false
      })
    })
  }

  _displayFilm(){
    const film = this.state.film
    if(film != undefined){
      return(
        <ScrollView style={styles.scrollView_container}>
          <Image
            style = {styles.image}
            source = {{uri: getImageFromApi(film.backdrop_path)}}
          />
          <Text style={styles.title_text}>{film.title}</Text>
          <Text style={styles.description_text}>{film.overview}</Text>
          <Text style={styles.default_text}>Note : {film.vote_average} / 10</Text>
        </ScrollView>
      )
    }
  }

  render() {
    return (
      <View style={styles.main_container}>
        {this._displayFilm()}
      </View>
    )
  }
}

const styles = StyleSheet.create({
  main_container: {
    flex: 1
  },
})

const mapStateToProps = (state) => {
  return state
}

export default connect(mapStateToProps)(FilmDetail)

This is my package.json

 {
      "main": "node_modules/expo/AppEntry.js",
      "scripts": {
        "start": "expo start",
        "android": "expo start --android",
        "ios": "expo start --ios",
        "eject": "expo eject"
      },
      "dependencies": {
        "expo": "^32.0.0",
        "numeral": "^2.0.6",
        "react": "16.5.0",
        "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
        "react-native-modal": "^9.0.0",
        "react-navigation": "^3.6.1",
        "react-redux": "^7.0.1",
        "redux": "^4.0.1"
      },
      "devDependencies": {
        "babel-preset-expo": "^5.0.0"
      },
      "private": true
    }

Upvotes: 7

Views: 5792

Answers (7)

Giii
Giii

Reputation: 7

I use yarn to solve it (or npm if you want)

yarn add react-redux

It will update your 'react-redux' to latest version and it solve my problem. Hope it helpful.

Upvotes: 1

Caio Kretzer
Caio Kretzer

Reputation: 169

If you're using expo, you have to downgrade your react-redux and clear expo cache.

npm i [email protected]

npm i

expo r -c

Upvotes: 1

Manny
Manny

Reputation: 11

Had the same issue. It was solved by switching to yarn and reinstalling all modules with the following setup:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject"
  },
  "dependencies": {
    "@expo/vector-icons": "^9.0.0",
    "date-fns": "^1.30.1",
    "expo": "^32.0.6",
    "moment": "^2.24.0",
    "native-base": "^2.10.0",
    "react": "16.8.6",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
    "react-native-elements": "^0.19.1",
    "react-navigation": "^3.0.9",
    "react-redux": "^6.0.0",
    "redux": "^4.0.1"
  },
  "devDependencies": {
    "babel-preset-expo": "^5.1.1",
    "schedule": "^0.4.0"
  },
  "private": true
}

Upvotes: 0

Ishmael Sibisi
Ishmael Sibisi

Reputation: 69

I was having the same issue and and got fixed when I downgraded my react-redux back to version 4.4.9

npm install [email protected] 

or if you using yarn

yarn add [email protected]

Hope it works for you too. But make sure first this dramatic downgrade doesn't affect your project in a negative way.

Upvotes: 0

Samuel Vera
Samuel Vera

Reputation: 141

Had a while ago what I think is the same problem as you. I updated to the latest React version with:

npm install react@latest

Then installed version 0.4.0 of the react schedule package with:

npm i [email protected] --save-dev

And downgraded react-redux with

npm i [email protected]

at least for the moment my problem is solved, hope it works with yours.

Upvotes: 8

Da Teng
Da Teng

Reputation: 3

It happened because you used the most recent version of react-redux dependent on react.memo API which is not supported by the Expo SDK. To solve this problem, you can install the older version of react-redux such as version 6.0.

Upvotes: 0

Giovanni Lobitos
Giovanni Lobitos

Reputation: 852

Just update your React to the latest version. It's backward compatible, so no need to worry.

npm install react@latest

React.memo is only available on React version 16.6 and above.

https://reactjs.org/blog/2018/10/23/react-v-16-6.html

Upvotes: 0

Related Questions