Skip to content

Instantly share code, notes, and snippets.

@kubk

kubk/mobx-6-cache.js

Created Apr 20, 2021
Embed
What would you like to do?
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