使用连接时出错(react-redux 库的功能) [英] error when using connect (function of the react-redux library)

查看:52
本文介绍了使用连接时出错(react-redux 库的功能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组件类,我使用 react-redux 来连接 redux 存储,但是当我尝试将组件传递给 connect 函数时出现错误.

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 不是函数.(在 '_react.default.memo(ConnectFunction),'_react.default.memo' 未定义)

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

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

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

我附上生成错误的图片

这里是调用connect的类的内容

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

电影细节

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)

<小时>

这是我的 package.json


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
    }

推荐答案

前阵子遇到了和你一样的问题.我更新到最新的 React 版本:

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

然后安装了 0.4.0 版的 react schedule 包:

Then installed version 0.4.0 of the react schedule package with:

npm i schedule@0.4.0 --save-dev

并用

npm i react-redux@6.0.1

至少目前我的问题已经解决了,希望对你有用.

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

这篇关于使用连接时出错(react-redux 库的功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆