show.tsx 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import * as React from 'react';
  2. import {RouteComponentProps} from 'react-router'; //eslint-disable-line no-unused-vars
  3. import {Link} from 'react-router-dom';
  4. interface Pokemon {
  5. id: number;
  6. nickname: string;
  7. }
  8. interface PassedRouteProps {
  9. id?: string;
  10. }
  11. interface State {
  12. pokemon: Pokemon;
  13. }
  14. class PokemonShow extends React.Component<RouteComponentProps<PassedRouteProps>, State> {
  15. public state = {
  16. pokemon: {
  17. id: null,
  18. nickname: null,
  19. },
  20. };
  21. public async componentDidMount(): Promise<void> {
  22. try {
  23. this.setState({pokemon: {id: 1, nickname: 'Bulbasaur'}});
  24. } catch (err) {
  25. // eslint-disable-next-line no-console
  26. console.log(JSON.stringify(err, null, 2));
  27. }
  28. }
  29. public render(): JSX.Element {
  30. return (
  31. <>
  32. {this.state.pokemon.id}: {this.state.pokemon.nickname}
  33. <p>
  34. <Link to={`${this.props.match.url}/404`}>404 page</Link>
  35. </p>
  36. </>
  37. );
  38. }
  39. }
  40. export default PokemonShow;