Never miss a beat

Join my newsletter.

Tag: react

Testing React Components with React Testing Library

Published: 2/15/2020

Testing react components with React Testing Library can be tricky, so I decided to try something new and put together a video demonstrating how to test your react components. I’ll work on improving the audio quality going forward, but I’d love to know your thoughts! Wanna see more content like this in the future? Lemme know!

Managing Authentication with React's useContext Hook

Published: 2/11/2020

Contexts are a commonly used tool when building React libraries, but are often overlooked when building an application in React. I don’t believe that should be the case, as useContext can provide you a powerful alternative (but lightweight) alternative to tools like Redux when managed carefully. The classic example of using a context is to declare an app theme but we can use them for so much more than that. In fact, we’re going to leverage a context today to demonstrate how simple…

Understanding React Lifecycle Methods

Published: 2/5/2020

React Lifecycle Methods are one tricky piece of business, especially if you’re coming from a framework that doesn’t have their own. Thankfully, they’re fairly similar to Android’s lifecycle methods and it wasn’t long before I was able to grasp them. React has changed a lot over the past few years and it’s lifecycle methods are no exceptions. In fact, with the release of hooks, the idea of lifecycles were shaken once more! React hooks can often be seen as a way to simplify the lifecycle process…

How do I use TypeScript with React?

Published: 1/11/2020

React is allowing developers to iterate faster and build safer, more reliable frontend applications than we were building many years ago. TypeScript , a relatively new addition to the “JavaScript Alternatives” scene, also aims to add a new level of safety in the form of type safety. Naturally, it makes sense for us to want to use TypeScript to write React components. But how do you do that? There are two different ways. Using the –typescript flag with create-react-app If you’re starting a new…

Fetching Data with React Hooks

Published: 1/9/2020

React hooks have changed the way that I (and arguably the React Community) prefer to build components . I’ve been working on a GraphQL project for a while, and when we migrated to functional components and hooks, I was able to use Apollo’s hooks for my data fetching needs. However, I find myself now working on a new project that doesn’t use GraphQL. Consequentially, I find myself wondering “How do I fetch data with React Hooks?” If you’d just like to see a codepen example of the code, you can…

Autosaving with React Hooks

Published: 12/21/2019

React hooks have really changed the game for me when it comes to building react components. However, I’ve found that writing autosaving functionality is a little less obvious via hooks. Thankfully, it is still possible (and arguably a lot cleaner) when using hooks. We can accomplish autosaving functionality through use of useEffect . You’ll also need a way to post the data to your server. In my case, I’m using Apollo’s useMutation hook as well. This allows me to post a graphql mutation from a…

Auth Guarding React Router Routes

Published: 10/27/2019

A common theme in web applications is to serve specific content to authenticated users while serving other content to everyone else. I’ve heard this referred to in the past as “auth guarding” specific content. In this case of our example today, we want to auth guard react-router routes. There are a couple of different ways to do this, but I’ve found a pattern that I really like that uses higher-order function components to help create the functionality that would be expected of an auth guarded…