React、Javascript - 在“Connect(App)”的上下文中找不到“store”

我正在尝试将 propTypes 和 mapStateToProps 添加到 React-intl 的 App.js 组件中。但它说在“Connect(App)”的上下文中找不到“商店”。


我的 App.js


import React, { Component } from "react";

import { BrowserRouter as Router, Route, Switch } from "react-router-dom";

import jwt_decode from "jwt-decode";

import setAuthToken from "./utils/setAuthToken";

import { setCurrentUser, logoutUser } from "./actions/authActions";

import PropTypes from "prop-types";

import { connect } from "react-redux";


import { Provider } from "react-redux";

import store from "./store";


import PrivateRoute from "./components/common/PrivateRoute";


import Navbar from "./components/layout/Navbar";

import Footer from "./components/layout/Footer";

import Register from "./components/auth/Register";

import Login from "./components/auth/Login";

import Main from "./components/main/Main";

import Account from "./components/main/Account";


import { IntlProvider } from "react-intl";

import "./App.css";


// Check for token

if (localStorage.jwtToken) {

  // Set auth token header auth

  setAuthToken(localStorage.jwtToken);

  // Decode token and get user info and exp

  const decoded = jwt_decode(localStorage.jwtToken);

  // Set user and isAuthenticated

  store.dispatch(setCurrentUser(decoded));


  // Check for expired token

  const currentTime = Date.now() / 1000;

  if (decoded.exp < currentTime) {

    // Logout user

    store.dispatch(logoutUser());

    // TODO: Clear current Profile


    // Redirect to login

    window.location.href = "/login";

  }

}



说“无法在“Connect(App)”的上下文中找到“store”。要么将根组件包装在 a 中,要么在连接选项中将自定义 React 上下文提供者和相应的 React 上下文消费者传递给 Connect(App)。 ”


守着一只汪
浏览 165回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript