Never miss a beat

Join my newsletter.

The Archives

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…

Typescript: What is a Partial?

Published: 1/10/2020

A common theme in TypeScript is to define an interface for a data structure. Additionally, it’s fairly common to post data structures to an HTTP endpoint to create resources. You may even find yourself posting another structure with some of the same properties to update that data structure. Instead of creating another interface for the update, in this example, is where the use of Typescript’s Partial comes in to play. Imagine that we have the following interface. It’s safe to assume that there…

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…

Introducing the Design Doc Podcast

Published: 11/11/2019

Hey there! I’ll keep this brief, as all of the good content for this post is audio. Yesterday, I worked with a close friend of mine to release our first episode of the Design Doc podcast. That’s the podcast where I dig into questions about personal projects from experienced Software Engineers and we talk through some of the choices they’ve made, issues they’ve run into, and more. You can find Design Doc anywhere podcasts are found (if you can’t, please let me know and ill work to get it listed…

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…