为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

守着一只汪 2021-06-09 17:01:31
我正在尝试将 propTypes 和 mapStateToProps 添加到 React-intl 的 App.js 组件中。但它说在“Connect(App)”的上下文中找不到“商店”。我的 App.jsimport 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 tokenif (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)。 ”
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 164 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信