Created
July 15, 2019 17:05
-
-
Save radzserg/071590bc00b17c34c3169f24a9911392 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
| /* | |
| /ProductUpdatePage | |
| - connected.ts | |
| - ProductUpdatePage.ts | |
| - index.ts | |
| - saga.ts | |
| - reducer.ts | |
| */ | |
| // ProductUpdatePage.ts | |
| interface IProps extends WithTranslation { | |
| // my main component have no idea how this action works | |
| // does it use API, storage or whatever | |
| saveProduct: (productData: ProductData) => void; | |
| } | |
| export default class ProductUpdatePage extends Component<IProps> { | |
| onSubmit = () => { | |
| // build data from form | |
| this.props.saveProduct(productData); | |
| } | |
| render() { | |
| // render form | |
| return ( | |
| <form onSubmit={this.onSubmit}> | |
| ... | |
| ) | |
| } | |
| } | |
| // connected.ts or HOC version | |
| interface IDispatchToProps { | |
| saveProduct: (productData: ProductData) => void; | |
| } | |
| const mapDispatchToProps = (dispatch: Dispatch): IDispatchToProps => { | |
| return bindActionCreators({ saveProduct }, dispatch); | |
| }; | |
| export default connect<IStateToProps, IDispatchToProps>( | |
| null, // define mapStateToProps you need | |
| mapDispatchToProps | |
| )(ProductUpdatePage); | |
| // index.ts | |
| import ProductUpdatePage from "./connected"; | |
| export default ProductUpdatePage; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment