Skip to content

Instantly share code, notes, and snippets.

@radzserg
Created July 15, 2019 17:05
Show Gist options
  • Select an option

  • Save radzserg/071590bc00b17c34c3169f24a9911392 to your computer and use it in GitHub Desktop.

Select an option

Save radzserg/071590bc00b17c34c3169f24a9911392 to your computer and use it in GitHub Desktop.
/*
/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