UNPKG

338 BPlain TextView Raw
1import { observable, AnnotationsMap } from "mobx"
2import { useState } from "react"
3
4export function useLocalObservable<TStore extends Record<string, any>>(
5 initializer: () => TStore,
6 annotations?: AnnotationsMap<TStore, never>
7): TStore {
8 return useState(() => observable(initializer(), annotations, { autoBind: true }))[0]
9}