TypeError: Object(...) 不是 react-redux 中的函数 [英] TypeError: Object(...) is not a function in react-redux

查看:68
本文介绍了TypeError: Object(...) 不是 react-redux 中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在 react-redux 中 createStore 时,我遇到了这个奇怪的错误.我不知道为什么我之前在不同的应用程序中这样做过它工作正常.

TypeError: Object(...) is not a function./src/index.jsC:/projects/facebook/facebook-react/src/index.js:1411 |从'./rootReducer'导入rootReducer;12 |从 './registerServiceWorker' 导入 registerServiceWorker;13 |>14 |const store = createStore(15 |根减速器,16 |composeWithDevtools(applyMiddleware(thunk))17 |);查看编译▶ 6 个堆栈框架被折叠.

这是我的文件

<块引用>

index.js

import { createStore, applyMiddleware} from 'redux';从'redux-devtools-extension'导入{composeWithDevtools};从redux-thunk"导入 thunk;从'react-redux'导入{提供者};从'./App'导入应用程序;从'./rootReducer'导入rootReducer;从 './registerServiceWorker' 导入 registerServiceWorker;const store = createStore(根减速器,composeWithDevtools(applyMiddleware(thunk)));ReactDOM.render(<浏览器路由器><提供者商店={商店}><应用程序/></提供者></BrowserRouter>, document.getElementById('root'));注册服务工作者();

<块引用>

rootReducer

import { combineReducers } from 'redux';从'./reducers/user'导入用户;导出默认的 combineReducers({用户});

<块引用>

reducer/用户

import { USER_LOGGED_IN } from '../types';导出默认函数 user(state = {}, action={}) {开关(动作.类型){案例 USER_LOGGED_IN:返回 action.user;默认:返回状态;} }

解决方案

我遇到了同样的问题:我可以让它在测试应用程序上工作,但无法将其转移到我的主项目中.检查了所有代码 100 次并进行了广泛研究,但找不到任何可以使 connect() 在不抛出TypeError: Object(…) is not a function"的情况下工作的内容

最后,我只需要更新我的主项目中的 react 和 react-DOM,因为我正在运行带有旧 react 的新版本 redux.

只需在您的项目文件夹中运行以下命令即可.

npm 更新

While I was trying to createStore in react-redux I get this strange error. I don't know why as I did this before in different app there it was working fine.

TypeError: Object(...) is not a function
./src/index.js
C:/projects/facebook/facebook-react/src/index.js:14
  11 | import rootReducer from './rootReducer';
  12 | import registerServiceWorker from './registerServiceWorker';
  13 | 
> 14 | const store = createStore(
  15 |     rootReducer,
  16 |     composeWithDevtools(applyMiddleware(thunk))
  17 | );
View compiled
▶ 6 stack frames were collapsed.

this is my file

index.js

import { createStore, applyMiddleware} from 'redux';
import { composeWithDevtools } from 'redux-devtools-extension';
import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import App from './App';
import rootReducer from './rootReducer';
import registerServiceWorker from './registerServiceWorker';

const store = createStore(
    rootReducer,
    composeWithDevtools(applyMiddleware(thunk))
);


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

rootReducer

import { combineReducers } from 'redux'; import user from './reducers/user';

export default combineReducers({
    user });

reducer/user

import { USER_LOGGED_IN } from '../types';

export default function user(state = {}, action={}) {
    switch (action.type) {
        case USER_LOGGED_IN:
            return action.user;
        default:
            return state;
    } }

解决方案

I had the same issue: I could get it to work on a test app and couldnt move it across to my main project. Checked all of the code 100 times and researched widely but couldnt find anything to make connect() work without it throwing "TypeError: Object(…) is not a function"

In the end all that was required was to update react and react-DOM in my main project as i was running a new version of redux with old react.

Just run the below in your project folder.

npm update

这篇关于TypeError: Object(...) 不是 react-redux 中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆