Daily iOS
SwiftUI

Unidirectional state flow

A used-goods listing screen built in SwiftUI has input fields, validation, submission, and error display all tangled together. If you reorganized it as a unidirectional state flow, in which direction would view events flow, and in which direction would state flow?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

The view only sends actions upward like .titleChanged and .submitTapped, the ViewModel (reducer) applies validation and the submit result to change state, and the view only reads that state and draws, so the data flow is unidirectional: actions up, state down.

Share a question