UNPKG

mobx-react-lite

Version:

Lightweight React bindings for MobX based on React 16.8+ and Hooks

10 lines (8 loc) 338 B
import { observable, AnnotationsMap } from "mobx" import { useState } from "react" export function useLocalObservable<TStore extends Record<string, any>>( initializer: () => TStore, annotations?: AnnotationsMap<TStore, never> ): TStore { return useState(() => observable(initializer(), annotations, { autoBind: true }))[0] }