redux/react-redux Provider TypeError: Object(...) is not a function

时间:2021-07-25 23:45:09

标签: javascript reactjs redux react-redux

为什么在尝试将 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 设置。我并没有真正使用它,这个我做过很多次的简单任务让我很难过。

0 个答案:

没有答案