Book Image

MobX Quick Start Guide

By : Pavan Podila, Michel Weststrate
Book Image

MobX Quick Start Guide

By: Pavan Podila, Michel Weststrate

Overview of this book

MobX is a simple and highly scalable state management library in JavaScript. Its abstractions can help you manage state in small to extremely large applications. However, if you are just starting out, it is essential to have a guide that can help you take the first steps. This book aims to be that guide that will equip you with the skills needed to use MobX and effectively handle the state management aspects of your application. You will first learn about observables, actions, and reactions: the core concepts of MobX. To see how MobX really shines and simplifies state management, you'll work through some real-world use cases. Building on these core concepts and use cases, you will learn about advanced MobX, its APIs, and libraries that extend MobX. By the end of this book, you will not only have a solid conceptual understanding of MobX, but also practical experience. You will gain the confidence to tackle many of the common state management problems in your own projects.
Table of Contents (17 chapters)
Title Page
Dedication
Packt Upsell
Foreword
Contributors
Preface
Index

An opinionated MobX with mobx-state-tree


MobX is very flexible in how you organize your state and apply the various actions and reactions. However, it does leave some questions for you to answer:

  • Should classes be used or just plain objects with extendObservable()?
  • How should the data be normalized?
  • How to deal with circular references when serializing the state?
  • And many more

mobx-state-tree is a package that gives you prescriptive guidance for organizing and structuring your observable state. Adopting the MST style of thinking gives you several benefits out of the box. In this section, we will explore this package and its benefits.

Models – properties, views, and actions

mobx-state-tree as the name suggests, organizes the state in a tree of models. It's a model-first approach, where each model defines the state that needs to be captured. Defining the model adds the ability to type-check the model assignments at runtime and guard you against inadvertent changes. Combining the runtime checks with...