Answer the question
In order to leave comments, you need to log in
Why action doesn't work?
Greetings) Why is the action not dispatched? I would be grateful for any help)
App.js
import React from 'react';
import './App.css';
import { connect } from 'react-redux';
import personsFetchData from '../actions/persons';
function App() {
React.useEffect(() => {
console.log(0); /* Здесь консоль отрабатывает */
personsFetchData("/api/persons")
});
return (
<div className="App">
<div>
</div>
</div>
);
}
const mapStateToProps = state => {
return {
persons: state.persons
};
}
const mapDispatchToProps = dispatch => {
return {
personsFetchData: (url) => dispatch(personsFetchData(url))
};
};
export default connect(mapStateToProps, mapDispatchToProps)(App);
const personsFetchData = (url) => {
console.log(1); /* Здесь консоль отрабатывает */
return (dispatch) => {
console.log(2); /* Здесь консоль УЖЕ не отрабатывает */
fetch(url)
.then(response => {
if(!response.ok){
throw new Error(response.statusText)
}
return response;
})
.then(response => {
response.json()
})
};
};
export default personsFetchData;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question