Created
April 20, 2021 09:26
-
-
Save kubk/864156b0bb795a8439bea7d6f9dd6315 to your computer and use it in GitHub Desktop.
Simple Mobx 6 cache example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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