Why I Stopped Reaching for a State Management Library
I've been working with Storybook for about 4 years now, and my opinions on form validation have changed more than I expected.
We had good intentions. We even had a document describing how form validation should work. The trouble was that the document and the code had quietly gone their separate ways.
Some background
The setup was ordinary: Storybook at the edges, React doing most of the heavy lifting, and a handful of scripts nobody wanted to own. It worked well until usage roughly doubled over a single quarter.
The first symptom was subtle. Nothing failed outright, but form validation kept drifting in the wrong direction, and every fix seemed to make the next one harder.
A simpler approach
The fix turned out to be smaller than expected. Instead of adding another layer, we removed one and leaned on what Storybook already gives you out of the box.
Stripped of the project-specific bits, it looks like this:
export function debounce<T extends (...args: any[]) => void>(fn: T, wait = 200) {
let timer: ReturnType<typeof setTimeout> | undefined;
return (...args: Parameters<T>) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), wait);
};
}
It's tempting to generalize this into a library. Resist that urge until you've needed it in at least three places.
A few things that helped along the way:
- Delete dead code aggressively; it's the cheapest refactor there is.
- Write the migration guide before writing the migration.
- Agree on what "done" means before the first pull request.
- Keep the old path around until the new one has survived a real incident.
Trade-offs
There are cases where this falls apart. If your team is very small or your traffic is very spiky, the extra moving parts may not pay for themselves.
The biggest cost was social, not technical. Changing how people think about form validation takes much longer than changing the code.
What's next
I don't think there's a universal answer here, but I hope this gives you a few ideas to try on your own project. If you do, I'd love to hear how it goes.