RSSAmplifier

Blog

Sam Dawson's Blog

Web Frontend Design and Development

samdawson.devRSS feed ↗44 posts

Latest posts

Talking to the computer

Communicating ideas and exploring them quickly While the term vibe coding has been controversial, I do think the sentiment hints towards a way you might want to work with these tools. Leaving aside…

Archiving Robust UI

Robust UI E-book Cover Long overdue, I've archived my Robust UI e-book landing page. While the content about React component testing strategies might be useful to some, I never got it to a final state…

AI coding - prototyping

Planning Using a model like o3 in ChatGPT can be useful to flesh out an idea and iterate before building anything. Once you are happy with the plan you can even ask o3 for an initial prompt to put…

AI coding - context

A large differentiator in the quality of output you will receive from AI coding tools depends on the quality of the AI model and the framework which it can act within, together often called an “Agent…

Do you need unit and end-to-end tests?

You might have a suite of end-to-end tests that cover your application well and you might be thinking do we need to duplicate our tests at a unit or integration test level also? Putting aside that end…

Private and public functions in React

With Frontend libraries like React, we often don't use classes. But the same public/private differentiation can be made through the keyword. Anything that has an is public and anything that doesn't…

Redux selector test duplication

When writing integration tests (tests that do minimal mocking) I often find myself duplicating test cases. In scenarios like this where I might have two functions that do similar things and share code…

Sharing code between gatsby-node and components

To share code between gatsby-node files and other components the shared file must use CommonJS syntax. For example: The exported stuff can then be used in gatsby-node.js with a require import and…

Testing Hooks - Hooks for mass consumption

This is part three in a series on Testing Hooks The final category of hook usage is one of utility. These are hooks from libraries or hooks that are used widely throughout your code. They often have a…

Testing Hooks - Hooks for code reuse

This is part two in a series on Testing Hooks In the last section where we shuffled around some code to make it more readable, we were not taking full advantage of the benefits of hooks which is to…

Testing Hooks - Hooks for code organization

This is part one in a series on Testing Hooks The first category of hook usage is code organization to make our code easier to read. This is usually in the form of breaking a component into smaller…

How to test React Hooks

The primary category of React hook usage is code reuse between components. When trying to determine a testing strategy for a particular hook a few more categories appear. One of code organization…

How to test Compound Components

For a quick overview on Compound Compounds check out this article. Compound components are made up of many component parts. The most effective way to test them is together, holistically. To achieve…

How not to GraphQL

If you're here you're probably second-guessing your usage of GraphQL. It's a great tool but if your not deliberate about your schema design it can create complexity. A misuse of it can happen in the…

How to test React Context

React Context is a tool for designing flexible Component APIs. How we test it depends on the situation, we are going to explore some of the situations you might find yourself in and the best way to…

How to test gatsby-node

This article will be enough to get you started with unit testing gatsby-node.js, we are not going to deep dive into every possible test you might need to make. First of all, you need to ask yourself…

How to test SVG Graphs

This article is walk-through of testing a React Bar Graph with Jest and React Testing Library. The style of tests documented here could also be called integration tests. The gold standard for UI…

Least effort feedback

A few months ago I added a feedback textbox to the bottom of every article. I wanted to know when someone finds there way to an article do they solve their problem. I think the textbox was too much…

Transforming data for simpler components

Often we can end up with complex logic in components because the shape of the data determines how we write our component code. Sometimes we are not in control of that data at all. If we can simplify…

How to make a dynamic interlocking image grid with CSS

tells CSS grid to slot in items where there is space. This shuffles around the visual order of the elements, the DOM tree remains in the original order. A dense layout can look something like this…

Goodbye presentational and container components?

I had been following the Presentational and Container pattern invented by Dan Abramov, although it seems that even Dan has changed his views on the usefulness of this pattern with the introductions of…

The snapshot testing tool

Kent C Dodds mentions in his article about snapshot testing when referring to a particular snapshot. "What makes this snapshot good is it can communicate the intent by the title of the snapshot" I…

Union type from an array of strings

Sometimes typescript can feel like duplication, describing code that is already static (constant). Heres one trick to mitigate that by generating a string literal union type from an array. The…

A less addictive slack experience

To some extent, it is the design of tools like slack that makes them addictive. To avoid the point of diminishing returns with slack usage, we can nudge ourselves to become less addicted by making…

Don't make assumptions about JS performance

After re-reading YDKJS: Async and Performance. I had the realization that I have been making over-optimizations. I had not taken into consideration JS engine optimizations. Iterators Like always using…

React Component API Design

This article will go over some component API design patterns at a high level without getting into implementation details of specific components. A Component API is the props of a component. When we…

Compound Components: What, Why and When.

What are Compound Components? It's a base component that expects to be combined with other component parts. Below the is the base component and the and components are the composable parts. It…

useSelector vs connect (react-redux)

React-redux hooks like and the can have the same outcomes. The main difference between them is their ability to nudge (guide) the way you write your components. Understanding what each of them…

When utility classes get out of control

Tailwinds utility classes make styling lighting fast (for me at least) but I have found there is a point where conditional styling can become hard to maintain because it concentrates the complexity in…

Compiling NPM packages with typescript

Update: You might be better off using TSDX "TSDX is a zero-config CLI that helps you develop, test, and publish modern TypeScript packages with ease" There are so many options for bundling javascript…

Reacts missing conditional class utility

AngularJS has ng-class for conditionally applying classes. This is a replacement for that in React. At accelo we are in the process of transitioning from AngularJS to React. We are not using a CSS-in…

Some handy git aliases

This is a list of git aliases I commonly use, mainly this is just a reference for myself for when I change computers or when someone sees me typing them and wants to know more. If you have any more…

Creating a chrome extension with parcel

This article is not a tutorial on how to build a chrome extension from scratch. Maybe you know how to make an extension with vanilla JS and now want to build it with your favorite frontend library. We…

Tailwind theming with CSS variables

This is a solution for implementing color themes with tailwind. It makes use of CSS variables which are great providing that you don't need to support IE11. Those CSS variables that are referenced in…

Guidelines for css utility classes

Never override them Avoid CSS where the utility class is overridden. For example, overriding with a child selector. You want them to be predictable everywhere you use them. A warning sign for breaking…

z-index strategies

Let's go over some ways to keep your z-index usage sane. All in one place Keeping all of your z-indexes in one place, in order. That way you can easily see what sits on top of what. The global file is…

Things I learned about media queries from Tailwind

I learned some things about media queries while looking into how they are used in Tailwind. It's a CSS library that generates utility classes, no prior knowledge about it is needed to follow along…

A gotcha when using gatsby, tailwind and purgecss

A problem I came across when using a mix-match of tailwind, purgecss and Gatsby is that selectors used in the generated pages were being stripped from the CSS. Tailwinds docs recommend using purgecss…

Creating category pages for gatsby markdown blogs

This article contains a strategy for creating category list pages from categories defined in a markdown article. There is an assumption of some basic knowledge of gatsby. Our end goal is to generate…

Inheritance media queries and css variables

This article aims to show an alternative to overriding properties directly. Instead we can use CSS variables with the help of inheritance and media queries. I think that this approach leads to CSS…

Theming with current color

This article explores using the currentColor property to theme elements, to avoid writing extra CSS to override color. In cases where you have an element that needs to have a few different colors the…

Magic numbers in css

A magic number is a number or value in code that does not have an explicit meaning. In CSS maybe we don't have to be too strict and not every number usage needs to be a variable. But I think the more…

My css color system

My approach to color usage is similar to a "no magic numbers" rule that you might find in javascript, where colors are always referenced from a variable. It's useful to think about color usage…

Moving elements on hover pattern

I like elements that move on hover to convey interactivity. A problem with this pattern is "flickering" that can happen when hovering over the space left behind. First lets make the button move up on…