-
Writing an Error Boundary
Errors can happen in React components for many reasons. In development mode, errors will cause React to spit up a bunch of red text into the browser. This is sometimes helpful for debugging the problem. In production mode, React will display a white screen (called the “white screen of death”) rather than report to the…
-
Prop Drilling
Prop drilling is a normal pattern and best practice in React. There are times, however, when ‘global’ data, such as user preferences or theming information must be passed to many different component and through multiple layers.
-
Conditional Rendering with Element Variables
The benefit of using this method for conditional rendering is that it’s easy to read, and you can have as many branches as you need.
-
Conditional Rendering with &&
Using the && operator is a quick and easy way to conditionally render a component. Unlike using an if/else statement, a switch statement, or the ternary operator, using && doesn’t provide a way to choose between 2 or more components to render.