简体   繁体   English

尝试导入错误:“getMoviesList”未从“./actions”导出; 反应错误 redux

[英]Attempted import error: 'getMoviesList' is not exported from './actions'; error in react redux

I'm trying to import a function 'getMoviesList' written in action/index.js but getting an error even though my code and paths are correct Please have a look on my App.js ( where I'm trying to import that function ) and./action/index.js ( where I have defined that function )我正在尝试导入用 action/index.js 编写的 function 'getMoviesList',但即使我的代码和路径正确,也会出现错误 请查看我的 App.js (我正在尝试导入 function ) and./action/index.js (我已经定义了 function )

App.js应用程序.js

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { getMoviesList } from './actions';

class App extends Component {

  componentDidMount() {
    this.props.dispatch(getMoviesList());
  }

  render() {
    
      return (
        <div className="App">
        <h1>HELLO MOVIES_LIST</h1>
          {
            this.props.movies ?
            this.props.movies.map((object) => {
              return (
                <div key={object.id}>
                  <h3>{ object.name }</h3>  
                </div>      
              )
            })
            : null
          }
          
      </div>
    );
  }
}

function mapStateToProps (state) {
  return {
    movies: state.movies
  }
}

export default connect(mapStateToProps)(App);

action/index.js动作/index.js

export default function getMoviesList () {
    // Go to the database and get data 
    return {
        type: 'MOVIES_LIST',
        payload: [
            {
                id: 1,
                name: 'dark'
            },
            {
                id: 2,
                name: 'scam 1992'
            },
            {
                id: 3,
                name: 'peaky blinders'
            }
        ]
    }
}

change import { getMoviesList } from './actions'; import { getMoviesList } from './actions'; to import getMoviesList from './actions'; import getMoviesList from './actions'; as getMoviesList function is exported as default.作为getMoviesList function 默认导出。 As a result, it should be imported without using curly braces.因此,应该在不使用花括号的情况下导入它。

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

相关问题 尝试导入错误:“addToCart”未从“../actions/cartActions”导出。 与 Redux - Attempted import error: 'addToCart' is not exported from '../actions/cartActions'. with Redux 尝试导入错误:“useDispatch”未从“react-redux”导出 - Attempted import error: 'useDispatch' is not exported from 'react-redux' 尝试导入错误:'未从 - Attempted import error:' is not exported from 反应错误“尝试导入错误:'TodoItem'未从'./Todoitem'导出。” - error in react " Attempted import error: 'TodoItem' is not exported from './Todoitem'. " 尝试导入错误:“PrivateRoute”未从“react-router-dom”导出 - Attempted import error: 'PrivateRoute' is not exported from 'react-router-dom' 尝试导入错误:“Toast”未从“react-bootstrap”导出 - Attempted import error: 'Toast' is not exported from 'react-bootstrap' 尝试导入错误:“路由”未从“react-router-dom”导出 - Attempted import error: 'Routes' is not exported from 'react-router-dom' 尝试导入错误:“Navigate”未从“react-router-dom”导出 - Attempted import error: 'Navigate' is not exported from 'react-router-dom' 尝试导入错误:“withRouter”未从“react-router”导出 - Attempted import error: 'withRouter' is not exported from 'react-router' 尝试导入错误:“Outlet”未从“react-router-dom”导出 - Attempted import error: 'Outlet' is not exported from 'react-router-dom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM