简体   繁体   English

类型错误:store.getState 不是函数 React-redux

[英]TypeError: store.getState is not a function React-redux

I'm trying to make a login form and it requires me to migrate my soloreac app in react + redux app.我正在尝试制作一个登录表单,它要求我在 react + redux 应用程序中迁移我的 soloreac 应用程序。 I'm facing many errors and stuck with TypeError: store.getState is not a function .我面临许多错误并坚持TypeError: store.getState is not a function I'm a newbie in this, any kind of help will be appriciated.我是这方面的新手,任何形式的帮助都会得到帮助。

Index.js file Index.js 文件

import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';
import Provider from "react-redux/es/components/Provider";
import {applyMiddleware, createStore} from "redux";
import * as promise from 'redux-promise';

// ReactDOM.render(<App />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.

const createstorewithmiddleware = applyMiddleware(promise)(createStore)

ReactDOM.render(
  <Provider store={createstorewithmiddleware}>
    <App />
  </Provider>, document.getElementById('root'),
);

serviceWorker.unregister();

App.js file: App.js 文件:

import { HashRouter, Route, Switch, Router, Link } from 'react-router-dom';
import './App.scss';
import {connect} from "react-redux";

import Home from "./screens/home";
import SignInScreen from "./screens/signInScreen";
import SignUpScreen from "./screens/signUpScreen";
import {checkUser} from "./actions/auth";


const loading = () => <div className="animated fadeIn pt-3 text-center">Loading...</div>;

// Containers
const DefaultLayout = React.lazy(() => import('./containers/DefaultLayout'));

// Pages
const Login = React.lazy(() => import('./views/Pages/Login'));

const Register = React.lazy(() => import('./views/Pages/Register'));
const Page404 = React.lazy(() => import('./views/Pages/Page404'));
const Page500 = React.lazy(() => import('./views/Pages/Page500'));

class App extends Component {
  componentDidMount() {
    this.props.checkUser();
  }

  render() {
    return (
      <HashRouter>
        <React.Suspense fallback={loading()}>
          <Switch>
            {/*<Route exact path="/login" name="Login Page" render={props => <Login {...props}/>} />*/}
            <Route exact path="/sign-in/" component={SignInScreen}/>
            <Route exact path="/sign-up/" component={SignUpScreen}/>

            {/*<Route exact path="/register" name="Register Page" render={props => <Register {...props}/>} />*/}
            <Route exact path="/404" name="Page 404" render={props => <Page404 {...props}/>} />
            <Route exact path="/500" name="Page 500" render={props => <Page500 {...props}/>} />
            <Route path="/" name="Home" render={props => <DefaultLayout {...props}/>} />
          </Switch>
        </React.Suspense>
      </HashRouter>
    );
  }
}

const mapStateToProps = (state) => ({
});

const mapDispatchToProps = (dispatch) => ({
  checkUser: () => dispatch(checkUser())
});

export default connect(mapStateToProps, mapDispatchToProps)(App);

I get this error.我收到这个错误。 I don't understand what file or code is causing this error.我不明白是什么文件或代码导致了这个错误。

TypeError: store.getState is not a function new Provider node_modules/react-redux/es/components/Provider.js:25 22 | TypeError: store.getState is not a function new Provider node_modules/react-redux/es/components/Provider.js:25 22 | store: store, 23 |商店: 商店, 23 | subscription: subscription 24 |订阅:订阅 24 | }; }; 25 | 25 | _this.previousState = store.getState(); _this.previousState = store.getState(); | | ^ 26 | ^ 26 | return _this;返回_this; 27 | 27 | } 28 | 28 | View compiled constructClassInstance node_modules/react-dom/cjs/react-dom.development.js:11787 11784 |查看编译后的constructClassInstance node_modules/react-dom/cjs/react-dom.development.js:11787 11784 | new ctor(props, context);新 ctor(道具,上下文); // eslint-disable-line no-new 11785 | // eslint-disable-line no-new 11785 | } 11786 | } 11786 | } 11787 | } 11787 | var instance = new ctor(props, context); var instance = new ctor(props, context); | | ^ 11788 | ^ 11788 | var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;实例状态:空; 11789 | 11789 | adoptClassInstance(workInProgress, instance);采用ClassInstance(workInProgress,实例); 11790 | 11790 | { {

尝试以不同的方式启动您的商店:

const createstorewithmiddleware = createStore(yourReducer, applyMiddleware(promise))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 store.getState 不是 function react-redux - store.getState is not a function react-redux 反应 Redux:TypeError:store.getState 不是 function - React Redux : TypeError: store.getState is not a function React Native TypeError store.getState不是一个函数 - React Native TypeError store.getState is not a function React store.getState 不是函数 - React store.getState is not a function TypeError:store.getState不是函数。 (在“ store.getState()”中,“ store.getState”未定义 - TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined 不同的问题:React store.getState 不是一个函数 - Different Problem: React store.getState is not a function TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined 我该如何解决这个问题? - TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined how can i resolve this problem? Redux:在reducer函数中调用store.getState(),这是一种反模式吗? - Redux: Calling store.getState() in a reducer function, is that an anti pattern? 我收到此错误:TypeError: store.getState is not a function - I am getting this error: TypeError: store.getState is not a function Provider.js:20 Uncaught TypeError: store.getState is not a function - Provider.js:20 Uncaught TypeError: store.getState is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM