Super lightweight Preact bindings for MobX based on Preact 10.x+ and Hooks.
Base version is aligned with mobx-react-lite
version.
For now Preact app to use MobX, we need preact/compat
(not just preact
) and bundler alias.
But for bundle size, I want to use MobX with preact
.
So, I've just copied mobx-react-lite
package and added some tweaks.
With this package, you can use minimum preact
package and limited mobx-react-lite
APIs.
Roughly speaking, mobx-preact-super-lite
= mobx-react-lite
- observer()
hoc.
API | mobx-react-lite | mobx-preact-super-lite |
---|---|---|
observer() | ✅ | (*1) |
<Observer> | ✅ | ✅ |
useLocalObservable() | ✅ | ✅ |
enableStaticRendering() | ✅ | ✅ |
- *1 Original implementation requires
memo()
andforwardRef()
, it meanspreact/compat
is needed.
API | mobx-react-lite | mobx-preact-super-lite |
---|---|---|
useObserver() | ✅ | ✅ |
useLocalStore() | ✅ | ✅ |
useAsObservableSource() | ✅ | ✅ |
observerBatching() | ✅ | (*2) |
observerBatchingOptOut() | ✅ | (*2) |
isObserverBatched() | ✅ | (*2) |
- *2 We opt it out automatically.
See original repository and user guide.