import React from 'react'; import { view } from 'react-easy-state'; import { Link } from 'react-router-dom'; import { Icon } from 'antd'; import { RouteComponentProps, withRouter } from 'react-router'; import store from 'src/store'; import Example from './Example'; import EMAILS from './emails'; import './index.less'; type Props = RouteComponentProps; interface State { examples: any; } class Emails extends React.Component { state: State = { examples: {}, }; componentDidMount() { const { type } = this.props.match.params; if (type && !store.emailExamples[type]) { store.getEmailExample(type); } } componentDidUpdate(prevProps: Props) { const { type } = this.props.match.params; const prevType = prevProps.match.params.type; if (type && type !== prevType && !store.emailExamples[type]) { store.getEmailExample(type); } } render() { const { type } = this.props.match.params; let content; if (type) { content = ; } else { content = EMAILS.map(e => (

{e.title} ({e.id})

{e.description}

)); } return (

{type && ( )} Emails

{content}
); } } export default withRouter(view(Emails));