After trying to import my function, I've got an error:
Module not found: Can't resolve 'fetchProducts' in 'C:\Users\lesha\Desktop\blog\src\components\HomePage'
Screen of my hierarchy:
I don't know where the problem is
HomePage.jsx
import React, { Component } from "react";
import "./HomePage.css";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import fetchProductsAction from "fetchProducts";
import { fetchProducts } from "../fetchMovies/fetchMovies.js";
class HomePage extends Component {
componentDidMount() {
fetchProducts();
}
render() {
return <div>asd</div>;
}
}
const mapStateToProps = state => {
return {};
};
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
fetchProducts: fetchProductsAction
},
dispatch
);
export default connect(
mapStateToProps,
mapDispatchToProps
)(HomePage);
fetchMovies.js
import {
fetchProductsPending,
fetchProductsSuccess,
fetchProductsError
} from "../../actions/index";
export function fetchProducts() {
return dispatch => {
dispatch(fetchProductsPending());
fetch(
"https://api.themoviedb.org/3/movie/top_rated?api_key=b05433b24b52d30bb0b22ecfd4f86001&language=en-US&page=1"
)
.then(res => res.json())
.then(res => {
if (res.error) {
throw res.error;
}
dispatch(fetchProductsSuccess(res.products));
console.log(res.products);
return res.products;
})
.catch(error => {
dispatch(fetchProductsError(error));
});
};
}