Skip to content

Instantly share code, notes, and snippets.

@kubk
Created April 20, 2021 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubk/864156b0bb795a8439bea7d6f9dd6315 to your computer and use it in GitHub Desktop.
Save kubk/864156b0bb795a8439bea7d6f9dd6315 to your computer and use it in GitHub Desktop.
Simple Mobx 6 cache example
class UsersStore {
isLoaded = false;
users = [];
constructor() {
makeAutoObservable(this)
}
loadUsers() {
if (this.isLoaded) {
return;
}
this.isLoading = true;
this.apiClient.usersFetch()
.then(action((users) => {
this.users = users;
this.isLoaded = true;
}))
.finally(action(() => this.isLoading = false))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment