| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import * as React from 'react';
- import {RouteComponentProps} from 'react-router'; //eslint-disable-line no-unused-vars
- import {Link} from 'react-router-dom';
- import {Pokemon} from '../../../api';
- interface Pokemon {
- id: number;
- nickname: string;
- }
- interface PassedRouteProps {
- id?: string;
- }
- interface State {
- pokemon: Pokemon;
- }
- class PokemonShow extends React.Component<RouteComponentProps<PassedRouteProps>, State> {
- public state = {
- pokemon: {
- id: null,
- nickname: null,
- },
- };
- public async componentDidMount(): Promise<void> {
- try {
- const data = await Pokemon.get(this.props.match.params.id);
- this.setState({pokemon: data.data});
- } catch (err) {
- // eslint-disable-next-line no-console
- console.log(JSON.stringify(err, null, 2));
- }
- }
- public render(): JSX.Element {
- return (
- <>
- {this.state.pokemon.id}: {this.state.pokemon.nickname}
- <p>
- <Link to={`${this.props.match.url}/404`}>404 page</Link>
- </p>
- </>
- );
- }
- }
- export default PokemonShow;
|