Bird
0
0

In a small Angular app with a few components sharing a simple numeric state, which approach best avoids NgRx complexity while keeping state consistent?

hard📝 Conceptual Q8 of 15
Angular - State Management
In a small Angular app with a few components sharing a simple numeric state, which approach best avoids NgRx complexity while keeping state consistent?
AUse a shared service with RxJS BehaviorSubject to manage and emit state changes
BImplement NgRx store with actions and reducers for all state updates
CKeep state only in the root component and pass it down via @Input() bindings
DUse localStorage to persist and share state between components
Step-by-Step Solution
Solution:
  1. Step 1: Identify shared state needs

    Multiple components require synchronized state.
  2. Step 2: Evaluate approaches

    Shared service with BehaviorSubject allows reactive updates without NgRx overhead.
  3. Step 3: Compare alternatives

    NgRx is complex for small apps; passing via @Input() is cumbersome; localStorage is not reactive.
  4. Final Answer:

    Use a shared service with RxJS BehaviorSubject to manage and emit state changes -> Option A
  5. Quick Check:

    BehaviorSubject enables simple reactive shared state [OK]
Quick Trick: Shared service with BehaviorSubject balances simplicity and reactivity [OK]
Common Mistakes:
  • Choosing NgRx for small, simple state sharing
  • Using localStorage expecting reactive updates
  • Passing state only via inputs causing prop drilling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes