Created
October 27, 2016 15:12
-
-
Save abiodun0/a2092e79d973d9eb69e65fe779b55686 to your computer and use it in GitHub Desktop.
Beauty of Compose
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 UpdateRoleForm from './updateRoleForm'; | |
const mapStateToprops = (state, ownProps) => { | |
return { | |
initialValues: ownProps.role, | |
form:`update_role_form${(ownProps.role.id).toString()}` | |
} | |
} | |
const mapDispatchToProps = (dispatch) => { | |
return { | |
serviceUpdateRole: (data, resolve, reject) => { | |
dispatch(RolesActions.serviceUpdateRole(data, resolve, reject)); | |
} | |
}; | |
}; | |
const reduxUpdateRoleForm = reduxForm({ | |
destroyOnUnmount: false, | |
})(UpdateRoleForm); | |
export default connect( | |
mapStateToprops, | |
mapDispatchToProps | |
)(reduxUpdateRoleForm); |
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 UpdateRoleForm from './updateRoleForm'; | |
import {compose} from 'redux'; | |
const mapStateToprops = (state, ownProps) => { | |
return { | |
initialValues: ownProps.role, | |
form:`update_role_form${(ownProps.role.id).toString()}` | |
} | |
} | |
const mapDispatchToProps = (dispatch) => { | |
return { | |
serviceUpdateRole: (data, resolve, reject) => { | |
dispatch(RolesActions.serviceUpdateRole(data, resolve, reject)); | |
} | |
}; | |
}; | |
const reduxUpdateRoleForm = reduxForm({ | |
destroyOnUnmount: false, | |
}); | |
const reduxUpdateRoleForm = compose(mapStateToProps, mapDispatchToProps, reduxUpdateRoleForm), | |
export default reduxUpdateRoleForm(updateRoleForm); |
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' | |
const UpdateRoleForm = ({role, serviceUpdateRole}) => { | |
return ( | |
<Panel> | |
<Field | |
name="name" | |
component={ (props) => { <input {...props.input} />} | |
placeholder="role name" | |
/> | |
<Field | |
name="description" | |
component={ (props) => { <input {...props.input} />} | |
placeholder="role description" | |
/> | |
</Panel> | |
) | |
} | |
export default UpdateRoleForm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment