In earlier versions of React, you were required to use classes if you needed to manage state. Now with hooks that isn’t the case. Let’s explore the options
You can write React components in two ways: As a function, or as a class. It can be confusing to understand which you should use and why. For devs brand new to React, they may not understand the history and recent changes between the two. If you ask online, everyone says to use function components. However, almost every tutorial, even the official documentation, favors classes. Why the divide?
The less you mutate your data, the better, and the easier it will be to reason about your code. The concept of not changing values is known as immutability. Handling immutability with objects can be tricky. Here are some examples for handling various use cases. Add or replace an element to an object Similar to adding […]
When working with tools like React and Redux, they discourage making direct edits to the state. Why is this? It’s more prone to errors. The less you mutate your data, the better, and the easier it will be to reason about your code. The concept of not changing values is known as immutability. It’s one […]
Part of the class components to function components series. In earlier versions of React, one of the biggest downsides to using function components over class components was that you could not use life cycle methods. What if you need to do something when your component mounts, like fetch some data or set some initial state? […]
There are situations where you do want to share state between multiple components, and you may not want to bring Redux into your architecture. In this tutorial, you’ll learn how to create your own mini-state management system.
If you are using class components, but want to use hooks, you can’t do so directly. One strategy for adding them is to use adapter components. Another strategy is to use higher-order components to pass along data from hooks as props. Here’s how
When the react-redux team released version 7.1.0, they added hooks to react-redux! Here’s a quick comparison of how it could change how you write components. First, a brief overview of the new toys useSelector: Pass in a function that takes the state as an argument and returns a value. Used to get a single value […]
Here’s a fairly benign component, that can give developers pause when its time to write unit tests for your components: There is only one thing worth testing here: That when we click the button, the function we passed in as a prop gets called. That prop function could be a complex chain of actions & […]