Portal v5.2

1 ibnlanre 1 7/27/2025, 4:35:36 PM npmjs.com โ†—

Comments (1)

ibnlanre ยท 1h ago
Just released Portal v5.2 yesterday and I'm really excited about the improvements

Major Performance Upgrades:

- Replaced useState/useEffect subscription pattern with useSyncExternalStore for better React 18+ compatibility and performance - Switched to Proxy-based stores instead of manually injecting methods - this gives much more stable references in React components AND enforces immutability by preventing direct property assignment (you can only modify state through $set) - Completely rewrote the internal cloning algorithm. It's now significantly faster than existing alternatives and I've released it as a separate library for anyone to use

New Features:

- useAsync: Built-in async state management with automatic loading/error/data states. No more manually tracking loading states! - useSync: Like useMemo but with deep dependency comparison for complex objects/arrays - useVersion: Deep dependency tracking that you can use with native React hooks (useMemo, useEffect, etc.) - createContextStore(): Initialize stores with React props/context data, eliminating the common prop-syncing boilerplate

Developer Experience:

- Primitive stores now handle circular references (honestly not sure why you'd need this since primitives get replaced entirely, but the consistency is nice!) - 600+ comprehensive tests covering edge cases, proxy behavior, circular references, async operations, and more

What makes Portal special: Portal automatically infers whether you need a primitive store (single values) or composite store (nested objects). The Proxy implementation means you get type-safe property access while maintaining strict immutability - direct assignments are silently ignored, forcing you to use $set for all mutations.

The new async hooks are game-changers for data fetching, and the deep dependency comparison means you can finally trust that your memoized computations only re-run when they actually need to.

If you're looking for type-safe state management that grows with your app's complexity and enforces good patterns, definitely worth checking out