Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
¿Cómo manejar la excepción no capturada en reaccionar y mostrar un mensaje simple de "error interno" en la interfaz de usuario?

En el lado del nodo,

 // Event 'uncaughtException' process.on('uncaughtException', (error, source) => { fs.writeSync(process.stderr.fd, error, source); });

¿Cuál es el equivalente de lo anterior para la interfaz con ReacT?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El concepto más cercano de uncoughtException en React se llama "Límites de error":
https://reactjs.org/docs/error-boundaries.html

Estos elementos detectarán cualquier error de representación que ocurra dentro de su subárbol.
Dentro del método de render , puede mostrar algún tipo de mensaje de "error interno".

about 4 years ago · Juan Pablo Isaza Report

0

React 16 introdujo límites de error a través de un método de ciclo de vida de componente de clase: componentDidCatch , sin embargo, hay algunas advertencias que debe leer en la documentación a continuación.

  • https://reactjs.org/docs/error-boundaries.html#introducing-error-boundaries

componentDidCatch

 /* * Implementation */ class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false }; } componentDidCatch(error, info) { // Display fallback UI this.setState({ hasError: true }); // You can also log the error to an error reporting service logErrorToMyService(error, info); } render() { if (this.state.hasError) { // You can render any custom fallback UI return <h1>Something went wrong.</h1>; } return this.props.children; } } /* * Usage */ <ErrorBoundary> <MyWidget /> </ErrorBoundary>

react-error-boundary

Sin embargo, en lugar de implementar lo anterior, recomiendo usar algo como react-error-boundary de Brian Vaughn.

Es flexible, permite la recuperación de errores y no depende externamente de ningún método de ciclo de vida de React.

  • https://github.com/bvaughn/react-error-límite
 import {ErrorBoundary} from 'react-error-boundary' const ErrorFallback = () => <div>Something went wrong</div> const myErrorHandler = (error: Error, info: {componentStack: string}) => { // Do something with the error // Eg log to an error logging client here } const ui = ( <ErrorBoundary FallbackComponent={ErrorFallback} onError={myErrorHandler}> <ComponentThatMayError /> </ErrorBoundary>, )
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!