Loading web/src/hooks/useGetStatesList.tsx +24 −3 Original line number Diff line number Diff line import { useState } from "react"; import { State } from "../infraestructure/entities/state"; import axios from "axios"; import axios, { AxiosError } from "axios"; import { TownDatasourceProd } from "../data/datasources/prod/town_datasource"; import { TownRepositoryProd } from "../data/repositories/prod/town_repository"; import { showErrorAxios } from "../utils/Messages"; const townDatasource = new TownDatasourceProd(); const townRepository = new TownRepositoryProd(townDatasource); Loading @@ -15,9 +16,29 @@ export const useGetStatesList = () => { setStatesList(states); }catch(error: any){ if(axios.isAxiosError(error)){ //console.log(error) error as AxiosError; showErrorAxios(error); } } } return {getStates, statesList}; const getStateById = async (idState: number) : Promise<State | null> => { let stateReturned: State | null = null; try{ const states = await townRepository.getStates(); states.forEach((state) => { if(state.stateId===idState){ stateReturned = state; return; } }) }catch(error: any){ if(axios.isAxiosError(error)){ error as AxiosError; showErrorAxios(error); } } return stateReturned; } return {getStates, statesList, getStateById}; } No newline at end of file Loading
web/src/hooks/useGetStatesList.tsx +24 −3 Original line number Diff line number Diff line import { useState } from "react"; import { State } from "../infraestructure/entities/state"; import axios from "axios"; import axios, { AxiosError } from "axios"; import { TownDatasourceProd } from "../data/datasources/prod/town_datasource"; import { TownRepositoryProd } from "../data/repositories/prod/town_repository"; import { showErrorAxios } from "../utils/Messages"; const townDatasource = new TownDatasourceProd(); const townRepository = new TownRepositoryProd(townDatasource); Loading @@ -15,9 +16,29 @@ export const useGetStatesList = () => { setStatesList(states); }catch(error: any){ if(axios.isAxiosError(error)){ //console.log(error) error as AxiosError; showErrorAxios(error); } } } return {getStates, statesList}; const getStateById = async (idState: number) : Promise<State | null> => { let stateReturned: State | null = null; try{ const states = await townRepository.getStates(); states.forEach((state) => { if(state.stateId===idState){ stateReturned = state; return; } }) }catch(error: any){ if(axios.isAxiosError(error)){ error as AxiosError; showErrorAxios(error); } } return stateReturned; } return {getStates, statesList, getStateById}; } No newline at end of file