show.tsx 1.1 KB

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