I have a component where I want to dispatch a Redux action through a function. What I do not understand is, the function is not executed. A console.log() right before and after the functioncall bar() gets logged, but when I try to console.log() from the function bar(), that has no effect what so ever... Why is that?
// Foo.js
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import React from 'react';
import { bar } from './actions';
const Foo = () => {
useEffect(() => {
console.log('I get logged');
bar();
console.log('I get logged too');
}, [])
return <Whatever> ... </Whatever>
};
const mapDispatchToProps = dispatch => {
return bindActionCreators({
bar,
}, dispatch)
};
const mapStateToProps = state => {
const { ... } = state
return {
...: ...
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Foo);
// actions.js
export const bar = () => async dispatch => {
console.log('I do not get logged');
await ...
dispatch({ type: ..., ... });
};