A way to use MobX-State-Tree without observer
Higher Order Components. This hook makes MST compatible with the React Compiler. MST stays reactive and type safe.
npm install mst-use-observable
import { t } from "mobx-state-tree";
import { useObservable } from "mst-use-observable";
const RootStoreModel = t
.model("RootStoreModel", {
count: t.number,
})
.actions((self) => ({
increment() {
self.count += 1;
},
decrement() {
self.count -= 1;
},
}));
const store = RootStoreModel.create({ count: 0 });
export default function App() {
const { count } = useObservable(store);
return (
<div className="App">
<p>{count}</p>
<button onClick={store.increment}>+</button>
<button onClick={store.decrement}>-</button>
</div>
);
}
Built with Bun. PRs welcome, especially if they include new test cases and docs.
bun install
bun test
bun run build
bun run typecheck
bun run lint # ESLint
bun run format # Prettier write