Chapter 7: Tips, Tricks, and Best Practices
In Chapter 6, Putting Pieces Together, we combined several key techniques of Jetpack Compose such as state hoisting, app theming, and navigation in a real-world example. ComposeUnitConverter
stores state in a ViewModel
and eventually persists it using the Repository pattern. In this chapter, I show you how to pass objects to a ViewModel
upon instantiation and use these objects to load and save data. In Chapter 3, Exploring the Key Principles of Compose, we examined features of well-behaved composable functions. Composables should be free of side effects to make them reusable and easy to test. However, there are situations when you need to either react to or initiate state changes that happen outside the scope of a composable function. We will cover this at the end of this chapter.
These are the main sections of this chapter:
- Persisting and retrieving state
- Keeping your composables responsive
- Understanding side effects ...