React Native · Mobile UI at native speed
How do you handle errors in a React Native app?
Short answer
Use error boundaries for render errors in React subtrees, catch expected failures at async and native boundaries, and install a global handler for uncaught JavaScript errors. Native crashes need crash reporting, not boundaries.
React error boundaries are class components that catch errors thrown during rendering, lifecycle methods and constructors of their descendants. They do not catch errors in event handlers, async callbacks or native code, so those need their own handling.
import React from "react";
import { Text, View } from "react-native";
type Props = { children: React.ReactNode };
type State = { error: Error | null };
export class ErrorBoundary extends React.Component<Props, State> {
state: State = { error: null };
static getDerivedStateFromError(error: Error): State {
return { error };
}
componentDidCatch(error: Error, info: React.ErrorInfo) {
console.error("render error", error, info.componentStack);
}
render() {
if (this.state.error) {
return (
<View>
<Text>Something went wrong.</Text>
</View>
);
}
return this.props.children;
}
}Layers of error handling
- Local try/catch around parsing, storage and network calls with a typed error result
- Error boundaries around screens or major sections for render failures
- A global handler for uncaught JavaScript errors that reports and recovers
- Crash reporting such as Sentry or Crashlytics for native crashes
- A retry or reload path rather than a dead-end error screen
Error boundaries reset only when their state changes. If a screen can recover, offer a retry that resets the boundary state or remounts the subtree with a new key. Log enough context to reproduce the issue, but never log tokens or personal data.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What errors do error boundaries not catch?
- 2How do you reset an error boundary?
- 3How do you report native crashes?
- 4What should a production fallback screen contain?
Say it in the interview
I layer error handling. Expected failures in network, storage and parsing are caught locally and returned as typed results. Render failures are caught by error boundaries around independent screen regions, so one broken widget does not blank the app. Uncaught JavaScript errors go to a global handler, and native crashes go to a crash reporter, because boundaries cannot catch those.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React Native mock interview and get scored feedback on depth, clarity and confidence.