[英]store.getState is not a function react-redux
reactjs 世界的新手。 我嘗試使用 redux 和 redux thunk 以及減速器,但我不完全了解它們是否都在一個 package 中。 我正在創建一個將使用這些項目的登錄名。 但我一直看到 store.getstate 不是 function。
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import {Provider} from 'react-redux';
const store = require('./store/index');
ReactDOM.render(
//<React.StrictMode>
<Provider store="{store()}">
<App />
</Provider>,
//</React.StrictMode>,
document.getElementById('root')
);
存儲/index.js
import {createStore} from 'redux'
import AllReducers from './reducers/AllReducers';
// import
const initialStates = {
auth: {
loggedIn: false,
user:{}
}
}
const store = createStore(AllReducers,initialStates);
export default store;
商店/reducers/AllReducers.js
import { combineReducers } from "redux";
import AuthReducer from "./AuthReducer";
const AllReducers = combineReducers({auth: AuthReducer})
export default AllReducers;
商店/reducers/AuthReducers.js
const AuthReducer = (state = {}, actions) => {
switch (actions.type) {
case 'value':
return state;
default:
return state;
}
}
export default AuthReducer;
我不斷收到 TypeError: store.getState is not a function 有人可以幫我至少提供一個關於如何捕獲此錯誤的建議,然后我將為我的學習做 rest。
謝謝。
我認為你在這里做錯了。 <Provider store="{store()}">
你應該寫<Provider store={store}>
我希望這個答案對你有幫助!!
<Provider store="{store()}">
中的問題。 您需要像這樣更新:
<Provider store={store}>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.