Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

403
Visualizações
El error en ReduxToolkit no puede manejar el error de API

Tengo una API para la aplicación meteorológica. Estoy tratando de conectarla correctamente, pero la probé ingresando valores incorrectos en el campo de entrada. Recibo un error pero no puedo resolver este error cuando ingreso datos incorrectos.

Error como este:

en Dashboard.js:55 Uncaught TypeError: Cannot read properties of undefined (reading '0')

y

Consider adding an error boundary to your tree to customize error handling behavior.

Puedes consultar todo el código desde aquí .

reductor adicional

 export const getDataReducer = createAsyncThunk('weatherData/getData', async (args, thunkAPI) => { const { rejectWithValue } = thunkAPI; try { const data = await axios.get(`https://api.worldweatheronline.com/premium/v1/weather.ashx?key=${api_key}&q=${args.country}&format=json&num_of_days=5`, { headers: {...} }) .then(res => res.data) .catch(e => console.log("fetchError",e)) console.log('new new new',data) return data } catch (error) { return rejectWithValue(error.message) } })

Rodaja

 [getDataReducer.pending]: (state, action) => { state.isLoading = true }, [getDataReducer.fulfilled]: (state, action) => { state.isLoading = false state.error = false state.getData = action?.payload?.data }, [getDataReducer.rejected]: (state, action) => { state.isLoading = false state.error = true state.getData = action?.payload?.data },

llamada redux

 const [country, setCountry] = useState(undefined) const {getData: APIData ,isLoading} = useSelector(state => state.getDataSlice) useEffect(() => { dispatch(getDataReducer({country})) },[dispatch, country])

cualquier ayuda, por favor

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Este error ocurrió debido a que la solicitud no está definida

 <WeatherInfo isLoading={isLoading} city={APIData && APIData.request ? APIData.request[0]?.query?.split(',')[0] : ''} country={APIData && APIData.request ? APIData.request[0]?.query?.split(',')[1] : ''} latitude={latitude} longitude={longitude} /> <Temp isLoading={isLoading} celsius={APIData && APIData.current_condition ? APIData.current_condition[0]?.temp_C : ''} fahrenheit={APIData && APIData.current_condition ? APIData.current_condition[0]?.temp_F : ''} weatherStatus={APIData && APIData.current_condition && APIData.current_condition[0].weatherDesc ? APIData.current_condition[0].weatherDesc?.value : ''} ForC={ForC} setForC={setForC} />

Así es como cambié el código, pero puedes volver a publicarlo en un código más limpio.

Cambié también en el codesandbox .

https://codesandbox.io/embed/quiet-browser-qiqtm7?fontsize=14&hidenavigation=1&theme=dark

mejor.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda