show.tsx 806 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {Link} from 'react-router-dom';
  4. import {Pokemon} from '../../../api';
  5. class PokemonShow extends React.Component {
  6. static propTypes = {
  7. match: PropTypes.object.isRequired,
  8. };
  9. state = {
  10. pokemon: {},
  11. };
  12. async componentDidMount() {
  13. try {
  14. const data = await Pokemon.get(this.props.match.params.id);
  15. this.setState({pokemon: data.data});
  16. } catch (err) {
  17. // eslint-disable-next-line no-console
  18. console.log(JSON.stringify(err, null, 2));
  19. }
  20. }
  21. render() {
  22. return (
  23. <>
  24. {this.state.pokemon.id}: {this.state.pokemon.nickname}
  25. <p>
  26. <Link to={`${this.props.match.url}/404`}>404 page</Link>
  27. </p>
  28. </>
  29. );
  30. }
  31. }
  32. export default PokemonShow;