Skip to content

Instantly share code, notes, and snippets.

@3nvi
Last active March 5, 2019 19:42
Show Gist options
  • Save 3nvi/3d75a87adb7fa6d5bb2f5ff9eb4f89f1 to your computer and use it in GitHub Desktop.
Save 3nvi/3d75a87adb7fa6d5bb2f5ff9eb4f89f1 to your computer and use it in GitHub Desktop.
// actions.js
export const fireAction = item => ({ type: 'ACTION', payload: { item } });
// Component.jsx
import React from 'react';
import { connect } from 'react-redux';
import { getItems } from './selectors';
function MyComponent({ item, fireActionWithItem }) {
return <button onClick={fireActionWithItem}>{item}</button>
}
const mapDispatchToProps = (dispatch, ownProps) => ({
fireActionWithItem: () => dispatch(fireAction(ownProps.item))
});
export default connect(null, mapDispatchToProps)(MyComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment