Skip to content

Instantly share code, notes, and snippets.

@rommsen
Created April 6, 2016 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rommsen/ec707755511150590d957a13d8e08525 to your computer and use it in GitHub Desktop.
Save rommsen/ec707755511150590d957a13d8e08525 to your computer and use it in GitHub Desktop.
import React from "react";
import {connect} from "react-redux";
import {changingOfMonthFeeWasRequested} from "./monthDucks";
import ChangeMonthFeeForm from "./ChangeMonthFeeForm";
/**
* component
*/
export const Month = ({showForm, month, onClick}) => {
return (
<tr>
<td>
{month.name}
</td>
<td>
{month.year}
</td>
<td>
{showForm
? <ChangeMonthFeeForm month={month}/>
: <a onClick={onClick}>{month.amount}</a>
}
</td>
</tr>
);
};
// ownProps contains the props of the rendered component
function mapStateToProps(state, ownProps) {
return {
showForm: state.app.showChangeMonthFeeForm === ownProps.month.id,
}
}
function mapDispatchToProps(dispatch, ownProps) {
return {
onClick: () => {
dispatch(changingOfMonthFeeWasRequested(ownProps.month.id));
}
}
}
/**
* container
*/
export default connect(mapStateToProps, mapDispatchToProps)(Month);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment