Reader small image

You're reading from  Hands-On Design Patterns with React Native

Product typeBook
Published inSep 2018
Reading LevelExpert
PublisherPackt
ISBN-139781788994460
Edition1st Edition
Languages
Right arrow
Author (1)
Mateusz Grzesiukiewicz
Mateusz Grzesiukiewicz
author image
Mateusz Grzesiukiewicz

Mateusz Grzesiukiewicz has worked on numerous big projects, including an investment banking platform at Goldman Sachs, a Jira project management tool at Atlassian, and a recruitment portal at GoldenLine. All of these projects served millions of people, which made them great opportunities to test scalability and the industry's best design patterns. He strives to popularize the common patterns and help people grow their technology at scale. He has spent hundreds of hours teaching, for instance at a private programming school called Coder's Lab. He has over 5,000 students registered on his online React course on Udemy. He would love to bring programming to every household, hence this bookHands-On Design Patterns with React Native.
Read more about Mateusz Grzesiukiewicz

Right arrow

Introduction to error boundaries

This is quite an overlooked feature that came with React version 16. As you should already know, JavaScript can throw errors. Such errors should not break your app, especially if it is from the financial sector. The regular imperative solution from JavaScript is a try-catch block:

try {
// helloWorld function can potentially throw error
helloWorld();
} catch (error) {
// If helloWorld throws error
// we catch it and handle gracefully
// ...
}

This approach is hard to use with JSX. Hence, the React team developed an alternative solution for React views. It's called Error Boundaries. Any class component can become an ErrorBoundary component, given that it implements the componentDidCatch function:

class AppErrorBoundary extends React.Component {
state = { hasError: false };

componentDidCatch() {
this.setState({ hasError...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Hands-On Design Patterns with React Native
Published in: Sep 2018Publisher: PacktISBN-13: 9781788994460

Author (1)

author image
Mateusz Grzesiukiewicz

Mateusz Grzesiukiewicz has worked on numerous big projects, including an investment banking platform at Goldman Sachs, a Jira project management tool at Atlassian, and a recruitment portal at GoldenLine. All of these projects served millions of people, which made them great opportunities to test scalability and the industry's best design patterns. He strives to popularize the common patterns and help people grow their technology at scale. He has spent hundreds of hours teaching, for instance at a private programming school called Coder's Lab. He has over 5,000 students registered on his online React course on Udemy. He would love to bring programming to every household, hence this bookHands-On Design Patterns with React Native.
Read more about Mateusz Grzesiukiewicz