Deleting a React view can be better than simplifying its state
A date-range switch looks like a harmless addition to a React component. In practice, it can introduce a second navigation model that has to stay in sync with the first. This happened in Twinly, a React and TypeScript b
A date-range switch looks like a harmless addition to a React component. In practice, it can introduce a second navigation model that has to stay in sync with the first.
This happened in Twinly, a React and TypeScript baby tracker designed for twins. Its home screen already provides a daily summary. A separate timeline temporarily offered both daily and weekly views.
The weekly timeline answers a different question: how did feeding, sleep and other care events change across several days? The daily view, meanwhile, overlapped with the home screen.
The interesting part of this change was not building another component. It was removing one.
The cost of a second navigation model
The previous timeline kept three pieces of navigation state: a display mode, the selected day and the start of the selected week.
A simplified excerpt of the old state declarations:
const [weekStart, setWeekStart] = useState(initialWeekStart);
const [displayMode, setDisplayMode] =
useState<"day" | "week">("day");
const [dayDate, setDayDate] =
useState(() => new Date(`${initialDate}T00:00:00`));
Moving to another day updated both the selected date and the start of its week. Switching to weekly mode also calculated the corresponding week start. An effect reset the selected day and week when the initial date changed.
None of these operations is particularly difficult. Together, however, they create more paths through the component. A change to date navigation now needs to account for two modes, their transitions and their reset behavior.
The extra button came with extra luggage.
First ask whether both views are necessary
React's documentation recommends avoiding redundant state when it can be calculated from other state. That is a useful starting point, but it does not tell us whether a product needs both modes in the first place.
The design decision here was to keep today's summary on the home screen and restore the timeline to a weekly-only view. With that decision, the component no longer needed to maintain a selected day or display mode.
The surviving date-navigation state was simply:
const [weekStart, setWeekStart] = useState(initialWeekStart);
useEffect(() => {
setWeekStart(initialWeekStart);
}, [initialWeekStart]);
These excerpts focus on date navigation; the actual component retains other state, such as the selected event.
This is not a recommendation to delete every view that shares data with another screen. A daily view might be essential in a product where users inspect individual days in detail. Here, the existing daily summary made the extra timeline mode redundant for the intended workflow.
Remove the implementation, not just its entry point
The change also deleted the unused daily timeline component and its dedicated CSS, rather than hiding the toggle and leaving the old rendering path behind.
The existing weekly navigation, event markers, tap-to-edit behavior and home-screen daily summary were preserved. The backend, persistence logic and data model did not need to change.
The pull request records successful TypeScript checking, a build and deployment to the development Firebase Hosting environment. It was subsequently merged. These checks establish that the implementation passed those recorded development steps; they do not establish that users became faster at completing tasks. That would require separate usability evidence.
A useful review question
Before adding state for a new display mode, identify the distinct user question that mode answers. If another surface already answers it, consider improving that surface instead.
When removing a mode, check the corresponding state, effects, conditional rendering, styles and interaction paths. Preserve the data and behaviors that remain useful.
React's guidance on choosing the state structure is a helpful companion to this approach. It addresses implementation complexity, while the product decision determines which complexity is worth keeping.
A smaller state machine is a nice result. A screen that asks fewer unnecessary questions of its users is the actual goal.
Disclosure: This article was generated by AI from verified Twinly development records.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.