Skip to content

Instantly share code, notes, and snippets.

@mikebridge
Created May 5, 2017 02:25
Show Gist options
  • Save mikebridge/0c30a19f8c6653c07349e901e97689bc to your computer and use it in GitHub Desktop.
Save mikebridge/0c30a19f8c6653c07349e901e97689bc to your computer and use it in GitHub Desktop.
TypeScript control with stacked HOCs
import * as React from "react";
import {IWithPersonalizationProps, withPersonalization} from "./withPersonalization2";
import {IWithNavigationProps, withNavigation} from "./withNavigation";
// This empty declaration is required
interface IWelcomeOwnProps {}
type IWelcomeProps = IWelcomeOwnProps & IWithNavigationProps & IWithPersonalizationProps;
class Welcome extends React.Component<IWelcomeProps, {}> {
constructor(props: IWelcomeProps) {
super(props);
this.onNameClicked = this.onNameClicked.bind(this);
}
public render(): JSX.Element {
return (
<div onClick={this.onNameClicked}>Welcome, {this.props.name}!</div>
);
}
private onNameClicked<P>(event: React.MouseEvent<P>) {
console.log(event);
event.preventDefault();
this.props.navigate();
}
}
export default withNavigation(withPersonalization(Welcome), "/settings");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment