Skip to content

Instantly share code, notes, and snippets.

@fuglu
Last active March 16, 2017 21:30
Show Gist options
  • Save fuglu/9a91c63fa9f16ffff50f8180cf301758 to your computer and use it in GitHub Desktop.
Save fuglu/9a91c63fa9f16ffff50f8180cf301758 to your computer and use it in GitHub Desktop.
import React from 'react';
import { connect } from 'react-redux';
import { actions as historyActions } from 'redux/modules/history';
export default (WrappedComponent) => {
class HistoryContainer extends React.Component {
static propTypes = {
fetchHistory: React.PropType.func.isRequired,
}
componentWillMount() {
this.props.fetchHistory();
}
render() {
return (
<WrappedComponent {...this.props} />
);
}
}
const mapStateToProps = state => ({
history: state.history,
});
const mapDispatchToProps = {
...historyActions,
};
return connect(mapStateToProps, mapDispatchToProps)(HistoryContainer);
};
import React from 'react';
import HistoryContainer from 'src/containers/HistoryContainer';
const HistoryTable = props => (
<table>
{props.history.map(item => (
<tr key={item.id}>
<td>{item.id}</td>
<td>{item.direction}</td>
<td>{item.from}</td>
<td>{item.to}</td>
<td><button onClick={() => props.deleteItem(item.id)}>Delete</button></td>
</tr>
))}
</table>
);
HistoryTable.propTypes = {
history: React.PropTypes.array.isRequired,
deleteItem: React.PropTypes.func.isRequired,
};
export default HistoryContainer(HistoryTable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment