反应:无效的挂接呼叫

时间:2020-07-18 18:29:06

标签: javascript reactjs react-native react-redux frontend

在我尝试使用react-cart-components并添加此行<Cart currency="CAD" />

之前,我的React应用程序运行良好。

错误:无效的挂钩调用。挂钩只能在身体内部使用 功能组件。可能发生以下情况之一 原因:

  1. 您可能使用了不匹配的React和渲染器版本(例如React DOM)
  2. 您可能正在违反挂钩规则
  3. 您可能在同一应用中拥有多个React副本

有趣的是,此应用程序在我朋友的计算机上可以正常工作,并且可以成功部署在heroku上,但在我的计算机上无法运行。我已经检查了我的react-dom和react-native版本,它们是最新的,并且我的应用程序中只有一个React副本,一切都很好。有什么想法吗?

import React, { useState, useEffect } from 'react';
import ToolBox from 'components/ToolBox';
import Product from 'components/Product';
import axios from 'axios';
import 'css/products.scss';
import { Cart, AddCartButton } from 'react-cart-components'

.........

const Products = () => {

.........

return (
    <div>
        <ToolBox  search={search} />
        <Cart currency="CAD" />
        <div className="products">
            <div className="columns is-multiline ">
                {
                    currentPage.map(pdct => {
                        return (
                            <div className="column is-2" key={pdct.productId}>
                                <Product product={pdct} />

                            </div>
                        )
                    })
                }
            </div>

        </div>
    </div>        
)

这是我朋友的package.json

  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "concurrently": "^5.2.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "is-empty": "^1.2.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.9.21",
    "node-sass": "^4.14.1",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "react-cart-components": "^2.1.0",
    "react-scripts": "^3.4.1",
    "redux": "^4.0.5",
    "twilio": "^3.47.0",
    "validator": "^13.1.1"

以下是我的

  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "concurrently": "^5.2.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "is-empty": "^1.2.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.9.21",
    "node-sass": "^4.14.1",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "react": "^16.13.1",
    "react-cart-components": "^2.1.0",
    "react-dom": "^16.13.1",
    "react-native": "^0.63.1",
    "react-redux": "^7.2.0",
    "react-scripts": "^3.4.1",
    "redux": "^4.0.5",
    "twilio": "^3.47.0",
    "uninstall": "0.0.0",
    "validator": "^13.1.1"
  }

0 个答案:

没有答案