Last active
March 16, 2017 21:30
-
-
Save fuglu/9a91c63fa9f16ffff50f8180cf301758 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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