I\'m working on a react-redux app and for some reason the action I call does not reach the reducer (in which I currently only have a log statement). I have attached the code
As Rick Jolly mentioned in the comments on your question, your onSearchPressed()
function isn't actually dispatching that action, because addToSaved()
simply returns an action object - it doesn't dispatch anything.
If you want to dispatch actions from a component, you should use react-redux to connect your component(s) to redux. For example:
const { connect } = require('react-redux')
class MainView extends Component {
onSearchPressed() {
this.props.dispatchAddToSaved();
}
render() {...}
}
const mapDispatchToProps = (dispatch) => {
return {
dispatchAddToSaved: () => dispatch(addToSaved())
}
}
module.exports = connect(null, mapDispatchToProps)(MainView)
See the 'Usage With React' section of the Redux docs for more information.