rsnext/examples/with-mobx/store.js
Joe Haddad 18a9c7e371
Improve linting rules to catch more errors (#9374)
* Update `packages/`

* Update examples

* Update tests

* Update bench

* Update top level files

* Fix build

* trigger
2019-11-10 19:24:53 -08:00

33 lines
799 B
JavaScript

import { action, observable } from 'mobx'
import { useStaticRendering } from 'mobx-react'
const isServer = typeof window === 'undefined'
// eslint-disable-next-line react-hooks/rules-of-hooks
useStaticRendering(isServer)
export class Store {
@observable lastUpdate = 0
@observable light = false
hydrate(serializedStore) {
this.lastUpdate =
serializedStore.lastUpdate != null
? serializedStore.lastUpdate
: Date.now()
this.light = !!serializedStore.light
}
@action start = () => {
this.timer = setInterval(() => {
this.lastUpdate = Date.now()
this.light = true
}, 1000)
}
stop = () => clearInterval(this.timer)
}
export async function fetchInitialStoreState() {
// You can do anything to fetch initial store state
return {}
}