使用连接时发生错误(react-redux库的功能)

Sou*_*tou 4 react-native react-redux

我有一个组件类,正在使用react-redux连接redux存储,但是当我尝试将组件传递给connect函数时遇到错误。

_react.default.memo不是函数。(在'_react.default.memo(ConnectFunction)中,'_react.default.memo'未定义)

wrapWithConnect C:\ Users \ SESA506797XmobileApp Gatherman \ node模块化react-redux \ lib \ components connectAdvanced.js:339:45

我附上生成的错误图片

这是调用connect的类的内容

电影细节

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)
Run Code Online (Sandbox Code Playgroud)

这是我的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
    }
Run Code Online (Sandbox Code Playgroud)

小智 6

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
Run Code Online (Sandbox Code Playgroud)

Then installed version 0.4.0 of the react schedule package with:

npm i schedule@0.4.0 --save-dev
Run Code Online (Sandbox Code Playgroud)

And downgraded react-redux with

npm i react-redux@6.0.1
Run Code Online (Sandbox Code Playgroud)

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