如何解决“找不到商店”的问题?

时间:2019-10-28 17:45:10

标签: javascript reactjs redux

我的商店有问题。当我在Chrome中打开开发工具时,出现此问题“找不到商店。请确保按照说明进行操作”。我使用了https://github.com/zalmoxisus/redux-devtools-extension的指令。这是我的代码:

./ configureStore / index.js

import {createStore, applyMiddleware, compose} from 'redux';
import rootReducer from '../reducers/index';
import thunkMiddleware from 'redux-thunk';


const initialState = {
  photos: []
}

export default function configureStore() {

  const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

  const enhancers = composeEnhancers(applyMiddleware(thunkMiddleware));

  const store = createStore(rootReducer,initialState,enhancers);

  return store
}

和./containers/Root.js

import React, {Component} from 'react';
import configureStore from '../configureStore/index.js';
import AsyncApp from './AsyncApp.js'
import {Provider} from 'react-redux';
import { render } from 'react-dom';

const store = configureStore();

export default class Root extends Component {
  render() {
    return (
      <Provider store={store}>
        <AsyncApp />
      </Provider>
    )
  }
}


和index.js

import 'babel-polyfill'

import React from 'react'
import { render } from 'react-dom'
import Root from './containers/Root.js'

render(<Root />, document.querySelector('.fixed-container'));

这是我的减速器。

import { combineReducers } from 'redux';
import {
  UPLOAD_PHOTOS_REQUEST,
  UPLOAD_PHOTOS_SUCCES,
  UPLOAD_PHOTOS_FAIL
} from '../actions/index.js'

const initialState = {
  isFetching: false,
  error: false,
  photos: []
}

function photos(state = initialState, action) {
  switch (action.type) {
    case UPLOAD_PHOTOS_REQUEST:
      return Object.assign({}, state, {
        isFetching: true,
        error: false
      })

    case UPLOAD_PHOTOS_SUCCES:
      return Object.assign({}, state, {
        isFetching: false,
        error: false,
        payload: action.payload,
        recievedAt: action.receivedAt
      })

    case UPLOAD_PHOTOS_FAIL:
      return Object.assign({}, state, {
        isFetching: false,
        error: true,
        payload: action.payload,
      })

    default:
      return {
        ...state,
        photos: state.photos
      }
  }
}

const rootReducer = combineReducers({
  photos
})

export default rootReducer;

0 个答案:

没有答案