简体   繁体   English

尝试导入错误:“./movieReducer”不包含默认导出(导入为“movieReducer”)

[英]Attempted import error: './movieReducer' does not contain a default export (imported as 'movieReducer')

I'm starting learn React + Redux , I'm doing a simple application for add or remove a movie in a basket.我开始学习 React + Redux ,我正在做一个简单的应用程序,用于在篮子中添加或删除电影。

But I have a problem on a reducer .但是我在减速器上有问题。 I try a lot of things without result...我尝试了很多事情都没有结果......

Thanks in advance :)提前致谢 :)

Here is my code :这是我的代码:

The reducer :减速机:

import '../actions/actionsTypes';

import { movies } from '../components/movie/data.json';

let initialState = []

movies.map((movie) => {
initialState.push({
id : movie.id,
title: movie.title,
year: year.title,
isAdd: false,
isRemove: false
})
return movie
})

const establishment = (state = {}, action) => {

    switch (action.type) {

        case ADD :

          if (state.id !== action.data.id)
               return state


        return (
          ...state,
          isAdd : !state.isAdd

        )

        case REMOVE :
          if (state.id !== action.data.id)
            return state

            return (
              ...state,
              isRemove : !state.isRemove

            )

        default:
          return state
    }

}

const establishmentsReducer = (state = initialState, action) => {

    switch (action.type) {

        case ADD :
          return state.map(movieState =>
            movie(movieState, action)
          )


        case REMOVE :
          return state.map(movieState =>
              movie(movieState, action)
          )

        default:
          return state

    }

}

export default movieReducer;

The connection of the reducer ( I know it's not useless but in the furtur will have to combine reducer ) :减速器的连接(我知道它不是没用,但在furtur将不得不结合减速器):

import { combineReducers } from 'redux';

import movieReducer from './movieReducer';


const allReducers = combineReducers({
movie : movieReducer
})

export default allReducers;

index.js :索引.js:

import React from 'react';
import ReactDOM from 'react-dom';

import { createStore } from 'redux';
import { Provider } from 'react-redux';

import allReducers from './reducers';

import './index.css';
import App from './components/App';
import * as serviceWorker from './serviceWorker';


const store = createStore(allReducers);

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

)

In your reducer, change:在您的减速器中,更改:

export default movieReducer;

To:到:

export default establishmentsReducer;

This is because you need to export an actually defined function or variable, in this case establishmentsReducer .这是因为您需要导出一个实际定义的函数或变量,在本例中为establishmentsReducer The code you shared in the reducer file does not have any functions/variables/expressions defined/named as movieReducer .您在 reducer 文件中共享的代码没有定义/命名为movieReducer任何函数/变量/表达式。

Another option would be to just change const establishmentsReducer = (state = initialState, action) => { to const movieReducer = (state = initialState, action) => { .另一种选择是只改变const establishmentsReducer = (state = initialState, action) => {const movieReducer = (state = initialState, action) => {

Hopefully that helps!希望这有帮助!

Bro you have import correctly:兄弟,您已正确导入:

import you reducer like :导入您的减速器,例如:

import { allReducers } from './reducers';从 './reducers' 导入 { allReducers };

This will solve your Problem.这将解决您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试导入错误:“./components”不包含默认导出(导入为“App”) - Attempted import error: './components' does not contain a default export (imported as 'App') index.js 尝试导入错误:“./App”不包含默认导出(导入为“App”) - index.js attempted import error: './App' does not contain a default export (imported as 'App') ./src/index.js 尝试导入错误:“./App.js”不包含默认导出(导入为“App”) - ./src/index.js Attempted import error: './App.js' does not contain a default export (imported as 'App') 尝试导入错误:“firebase/app”不包含默认导出(导入为“firebase”) - Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase') 尝试导入错误:“react-table”不包含默认导出(导入为“ReactTable”) - Attempted import error: 'react-table' does not contain a default export (imported as 'ReactTable') React JS 尝试导入错误:&#39;./Pathfinder/Pathfinder&#39; 不包含默认导出(导入为 &#39;Pathfinder&#39;) - React JS Attempted import error: './Pathfinder/Pathfinder' does not contain a default export (imported as 'Pathfinder') React-Redux:尝试导入错误:“./components/Score”不包含默认导出(导入为“Score”) - React-Redux: Attempted import error: './components/Score' does not contain a default export (imported as 'Score') [React.js] 尝试导入错误:&#39;./registerServiceWorker&#39; 不包含默认导出(导入为 &#39;registerServiceWorker&#39;) - [React.js]Attempted import error: './registerServiceWorker' does not contain a default export (imported as 'registerServiceWorker') 尝试导入错误:&#39;path-to-regexp&#39; 不包含默认导出(导入为 &#39;pathToRegexp&#39;) - Attempted import error: 'path-to-regexp' does not contain a default export (imported as 'pathToRegexp') 尝试导入错误:“uuid”在 React 中不包含默认导出(导入为“uuid”) - Attempted import error: 'uuid' does not contain a default export (imported as 'uuid') In React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM