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

Form validation


Filling up forms and validating fields is the classic use-case of the web. So, it's fitting we start here and see how MobX can help us simplify it. For our example, we will consider a User Enrollment form that takes in some standard inputs like first name, last name, email, and password.

The various states of enrollment are captured in the following figure:

The interactions

Looking at the preceding screenshot, we can see some standard interactions going on, such as:

  • Entering inputs for various fields
  • Validation on those fields
  • Clicking the Enroll button to perform a network operation

There are few other interactions here that do not meet the eye immediately:

  • Network-based validation for the email to ensure that we are not registering with an existing email address
  • Showing a progress indicator for the enroll operation

Many of these interactions will be modeled with actions and reactions in MobX. The state will, of course, be modeled with observables. Let's see how the Observables-Actions...