首页 > 解决方案 > redux/react-redux Provider TypeError: Object(...) is not a function

问题描述

为什么TypeError: Object(...) is not a function在尝试使用store道具时出现此错误<Provider store={store}/>

//Error in browser from Create-React-App
TypeError: Object(...) is not a function
   8 | var store = _ref.store,
   9 |     context = _ref.context,
  10 |     children = _ref.children;
> 11 | var contextValue = useMemo(function () {
     | ^  12 |   var subscription = new Subscription(store);
  13 |   subscription.onStateChange = subscription.notifyNestedSubs;
  14 |   return {
//index.js (in root of project)
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducers from './reducers/index.js'

const store = createStore(reducers);

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

// 我的reducers文件夹在同一级别。有两个文件:index.jsphotos.js

索引.JS

import { combineReducers } from 'redux'
import { Photos } from './photos'

const reducers = combineReducers({
    Photos
})

export default reducers

照片.JS

import { SET_PHOTOS } from '../actions/photos'

const DATA = {
    photos: []
}

export const Photos = (state = DATA, action) => {
    switch(action.type) {
        case SET_PHOTOS:
            return {
                ...state,
                photos: action.payload,
            };
        default:
            return state
    }
}

这是一个 create-react-app 设置。我并没有真正使用它,而我已经多次完成的这个简单任务让我很难过。

标签: javascriptreactjsreduxreact-redux

解决方案


推荐阅读