James DiGioia

my little web home

Gatsby, Next.js, and the distance to your data

At work, we recently decided to adopt Next.js to decouple our React front-end application from our Django API, so I’ve been working with it extensively over the past few weeks. In parallel, I’ve been working to migrate this very site to Gatsby, pulling in my reading list and my resume onto a new foundation, since […]Read more

useEffect’s function dependency pitfall

useEffect is a powerful hook provided in React 16.8, allowing you to sync data with the outside world. One of the minor annoyances with useEffect is its dependency array, which indicates to useEffect when it should rerun. Adding a function to the dependency array can cause major problems with useEffect. Let’s take a look at […]Read more

Why use TypeScript unknown for API response types

I recently extracted and released kefir-ajax, a fetch-like ajax library for Kefir. While I wrote the library in plain JavaScript, the library generates TypeScript typings from its JSDocs. As you can see here, the json method of the ObsResponse class returns TypeScript unknown, rather than the much more common any. Using unknown instead of any […]Read more

React Testing Tip: Reduce test duplication with a component render function

Whenever you write new tests for your React components, you’ll probably find your tests reusing the same interactions as tests you’ve already written. In multiple tests, you’ll click a button or change an input and assert that the React component you’re testing updates as expected. This comes up often enough when testing that I like […]Read more

I think not using snapshots makes the test-as-documentation much clearer. It explains what the developer was attempting to check with a given snapshot vs a more hand-wavey "it looks like this." This is particularly important if you want to assert snapshots in the middle of your tests / after changes, because then it’s a lot less clear what’s actually important. If you have a form that’s supposed to display error messages after attempting to submit invalid values. asserting against those messages specifically is much clearer than a snapshot.

One of the positives of "deep" snapshot testing is if a widely used component changes, all of the snapshot tests from all of the components that use it will also fail, which tells you which components to look at when checking to see if it still displays correctly.

pipe-dom: DOM manipulation with the F#-style pipeline operator

Last week, Babel released version 7.5.0, which included our implementation of the F#-style pipeline operator. If you’re not already aware, TC39 is exploring the potential of a pipeline operator in JavaScript. You can learn more about what’s going on with the operator here. At this point, we’ve got all 3 proposals in Babel, so the […]Read more

Using TypeScript tagged unions for loading state in Redux

Dealing with loading state is a core requirement of most apps you build. Every app needs data, that data almost always needs to be loaded from somewhere, so you need to manage your loading state. Redux doesn’t provide any particular structure for this, but combining it with TypeScript enables some useful patterns. Let’s take a […]Read more

What yo-yos taught me about being a developer

When I was in 4th grade, a yo-yo fad passed through my middle school. Because they were cheap, we all got one, and we were obsessed. We debated which brands were the best, which yo-yo style worked well, and how to do tricks. This was all pre-Internet and entirely word of mouth. We’d hang out […]Read more

Weekly Links – Nov. 25th, 2018

Transducers in JavaScript Array#reduce is one of those things that can be difficult to develop an intuition for, but if you can, what makes it powerful is how reducers (the function you pass to it) can be composed together. It’s an idea that I keep reading about in an attempt to get my head around […]Read more