[英]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.