example fix: hydrate method of the mobx store needs to be an action (#19522)

By default, MobX 6 and later require that you use `actions` to make changes to the state, otherwise, it issues a warning in the console, because the `hydrate` method of the `store.js` class hasn't been declared an action, you can see this warning if you try to load pages that use hydration (ssg, ssr).
This pull request fixes that.

More info about the behavior:
https://mobx.js.org/actions.html#disabling-mandatory-actions-
This commit is contained in:
Ivan V 2020-11-25 18:20:57 +01:00 committed by GitHub
parent 397a375b37
commit 14cb6556a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View file

@ -12,6 +12,7 @@ export class Store {
lastUpdate: observable,
light: observable,
start: action,
hydrate: action,
timeString: computed,
})
}

View file

@ -34,7 +34,7 @@ class Store {
stop = () => clearInterval(this.timer)
hydrate = (data) => {
@action hydrate = (data) => {
if (!data) return
this.lastUpdate = data.lastUpdate !== null ? data.lastUpdate : Date.now()