What I Learned Building Educational Content: Why Source Data and Solving State Are Separate
Separating problem data from users' solving state in a React education platform, and why data lifetime and reset boundaries come before screens.
Joohwan Yu · Founder, Full Stack Developer
Toris · Published
Contents
Looking back at building an educational content platform, what was complicated was not the number of screens. Even when showing the same problem, how far a student had gotten, what they had clicked, and what should remain when they came back were all different. Gathering the values a screen needs into one object made it hard to explain these differences.
Even on the Same Screen, the Lifetimes Differed
The problem text and the answer are the source of the content. The selected option and whether it has been submitted are state that arises during use. If you modify them together, even the meaning of “reset” becomes vague. When you press retry, only the selection should be cleared, yet the source would have to be rebuilt too, and when moving to another scene you have to decide each time which values should remain.
At the time, I separated the domain data from the solving state and managed the state keyed by problem ID. This choice was good not only because there was less data to store. It was because you could read in the code which values were owned by the content and which were owned by the user.
The Boundary, Written Down Again Now
What follows is not the source from back then, but a simplified type to explain that experience.
type Question = { id: string; answer: string };
type Attempt = { selected: string | null; submitted: boolean };
type Attempts = Record<string, Attempt>;
With this split, retrying becomes the task of resetting Attempts. Editing a problem and editing a student’s selection are also distinct tasks. It does require the assumption that IDs are stable, though. If you generate a new ID on every render, the benefit of separating the state disappears.
What I Regret Was the Unit of Verification
At the time I focused on finishing the features, and I was left regretting that tests and documentation were not sufficient. If I did it again now, I wouldn’t only check that the screen renders well. I would check these as separate scenarios: solving a problem, moving to the next scene and coming back, retrying, and refreshing. The first thing to check is whether they are actions that can be grouped under the same reset function.
Since this experience, I have a question I ask first when designing state. Before “where do I store it?”, I ask “who changes it, and when should it go away?” It wasn’t too late to choose the storage after that answer came out.
Related post: The Semware (셈웨어) Education Platform and the Move to Full Stack
Advertisement