Skip to content

Instantly share code, notes, and snippets.

@prashaantt
Last active December 2, 2016 09:49
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 prashaantt/4a9651a0b1d4096d797893178d50e821 to your computer and use it in GitHub Desktop.
Save prashaantt/4a9651a0b1d4096d797893178d50e821 to your computer and use it in GitHub Desktop.
import * as React from "react";
import { inject, observer } from "mobx-react";
import { withRouter, InjectedRouter } from "react-router";
import { UserStore } from "../../stores/UserStore";
interface MyComponentProps {
name: string;
countryCode?: string;
userStore?: UserStore;
router?: InjectedRouter;
}
@inject("userStore")
@withRouter
@observer
class MyComponent extends React.Component<MyComponentProps, {}> {
render() {
const { name, countryCode, userStore, router } = this.props;
return (
<div>
User: { name } <br />
Name: { userStore && userStore.getUserName(name) } <br />
Country: { countryCode && countryCode.toUpperCase() } <br />
<button
onClick={() => { router && router.push(`/users/${name}`) }}
>
Check out user
</button>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment