Hope u can help me to solve this problem! I'm a newcomer asking here so forgive me if I write something wrong.
Well, I've received a test for a job application and the purpose lookalike an old project of mine, it's a Pokedex basically, and I'm refactoring it in a new repository (I wanna use the packages at the latest version). It's been a long time since I've done the original one, and I was studying some other things so I wasn't focused on the react-router-dom updates and apparently useRouteMatch was deprecated. I've searched a lot about how to convert my old code according to the new hooks, but nothing showed up. So here is the code, made in React using Typescript:
interface PokemonParams {
pokemon: string;
}
interface Pokemon {
id: number;
name: string;
description: string;
height: number;
weight: number;
base_experience: number;
types: Array<Type>;
}
interface Type {
type: {name: string;};
}
const Pokemon: React.FC = () => {
const [pokemon, setPokemon] = useState<Pokemon | null>(null);
const { params } = useRouteMatch<PokemonParams>();
const loadPokemon = async () => {
const pokemon = await getPokemon(params.pokemon);
setPokemon(pokemon);
}
useEffect(() => {
loadPokemon();
}, [params.pokemon]);