What is the difference between declarative UI (Compose, SwiftUI, Flutter, React Native) and the older imperative style?
What the interviewer wants to hear
- Imperative UI means creating views and changing them step by step
- Declarative UI describes what the screen looks like for a given state
- The framework rebuilds or recomposes when state changes
- State should be the single source of truth, which reduces sync bugs
- Needs care with state ownership and avoiding unnecessary rebuilds
Model answer
In the imperative style, like Android XML views or UIKit, you build views once and then mutate them by hand: find the label, set its text, hide the spinner. It is easy to forget a step and leave the screen out of sync with the data. In declarative frameworks like Jetpack Compose, SwiftUI, Flutter and React Native, you write a function that describes the UI for the current state. When state changes, the framework re-runs that description and updates only what changed, through recomposition or diffing. This makes state the single source of truth and removes a whole class of sync bugs. The trade-off is that you must think about who owns each piece of state, and avoid expensive work or unstable inputs that cause too many rebuilds.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Mobile App Developer questions
- What is the difference between native and cross-platform mobile development? When would you choose each?
- Explain the lifecycle of a mobile app screen. Why does it matter?
- How do you handle network calls and errors in a mobile app?
- What is MVVM and why is it used in mobile apps?
- How do push notifications work in a mobile app?
- How do you run slow work like network calls or database reads in a mobile app without freezing the UI?
- What options do you have for storing data on the device, and how do you choose between them?
- How do you request runtime permissions like camera or location, and what do you do when the user says no?
- How do you make your app look good on different screen sizes, orientations and font sizes?