Easy Made Hard

22 November 2026

Introduction

Functional programming and Clojure have helped me a lot in my career. Even if I have mostly worked with JavaScript, the principles are still valuable. I find time and time again that deviating from them eventually gets punished as your application grows. I will cover some principles over several posts, this one will be about using a single source of truth.

This year the Clojure documentary was released, which inspired me to rewatch a couple of Rich Hickey's talks, including Simple Made Easy. One point he makes is the complexity and difficulty of stateful objects and the synchronisation of multiple such objects. In this post, I will outline an example I've come across in my work.

When working in an agile fashion, you want to be prepared for as many hypothetical future requirements as possible. You don't want to have to respond "Oof, that will be tricky due to some earlier decision we took". By having a single source of truth, you leave yourself in the best position to implement any requirement. You can read or update the data as needed (using pure functions!). If you have opted for a different approach for state management, you might find that something that should be easy is hard for you.

Work Example

We have a very typical React application at work. The user navigates through multiple pages, each page containing some inputs for the user to fill out. The data is saved to the backend API when a page is finished, with data from all pages being aggregated into a larger backend model. Consider the following example pages for a social application:

  1. User - Gathers data about the user.
  2. Group - The user creates a group and gathers details about members and admins.
  3. Event - The user creates an event, with a venue and an invitation list.

Our Approach

We structured this using React Hook Form, with a separate form per page. The overall application held all forms and ensured that the correct form for the current rendered page was made available in FormProvider.

function UserPage () {
    const allForms = useAllForms();
    const methods = allForms.userForm;
 
    return (
        <FormProvider {...methods}>
            ... user page components
        </FormProvider>
    );
}

This was great! Each tab was a separate concern, so we could have different teams working independently on them. As a bonus, React Hook Form gave us a lot of functionality right out of the box. We could define a schema and get validation for free. It managed form submits for saving the data to backend. It kept track of loading the initial data. It bought us speed.

Trouble Starts

Until one day it didn't. One day new requirements came in: "On the Event page, the default address for the Event should be the same as the address on the User page".

Okay, so the user was going to be able to select "Use the same address as on the User page" and if they do, we will display what that address was as a reminder. That data is encapsulated in a separate form that the Event page cannot access through React Hook Form's hooks. Not to be dismayed, the page can still access it via all forms.

function EventPage () {
    const allForms = useAllForms();
    const methods = allForms.eventForm;
    const userAddress = allForms.userForm.getValues("address");
 
    return (
        <FormProvider {...methods}>
            ... display user address as needed
        </FormProvider>
    );
}

This worked, but the intended separation was no longer there.

The next set of requirements were worse: "On the Group page, the first group admin should have the same user data as was filled out on the User page. When you change it in either place, it should update in both."

Here's roughly how we solved it, not very pretty.

function SynchronizationComponent() {
    const allForms = useAllForms();
    const userFormSetValue = allForms.userForm.setValue;
    const groupFormSetValue = allForms.groupForm.setValue;
 
    // Only demonstrating for the first name field
    const userFirstName = useWatch({
        control: allForms.userForm.control,
        name: "firstName",
    });
 
    const groupAdminFirstName = useWatch({
        control: allForms.groupForm.control,
        name: "admins[0].firstName",
    });
 
    useEffect(function () {
        groupFormSetValue("admins[0].firstName", userFirstName);
    }, [userFirstName, groupFormSetValue]);
 
    useEffect(function () {
        userFormSetValue("firstName", groupAdminFirstName);
    }, [groupAdminFirstName, userFormSetValue]);
 
    return null;
}

Easy Made Hard

Nothing about either of these requirements is particularly hard. So why was it hard to implement for us?

We had violated the principle of using a single source of truth for managing state. Instead, we had spread out the state across multiple stateful components. We were therefore left with the problem of synchronising them. That is a hard problem. Rich comes back to this again and again, that state is hard, and that synchronising stateful objects is hard.

When building an application, you never know what the final application is going to look like. Requirements change, the direction can change, and it's impossible to predict what features will be needed in the future. Therefore, you want to design a system that is open to change.

So what should we have done? We should have chosen a solution that didn't assume the isolation of the different pages. This would have meant spending some time upfront to design the application using a single source of truth. Yes, this would have been slower initially, but it would have been faster in the long run. This is another point Rich makes, that to buy long-term speed, you need to make an initial investment.

If we had used a single place to put all values, both examples become trivial. The first example would simply have read the address value as any other value. The second example would have read and written to the same fields from both pages.

In upcoming posts we will go into more depth about this principle and also look into several others.