RTK Persist - JS Library

The lightweight, zero-dependency library for
seamless Redux Toolkit state persistence.

Your State Persistence, Your Rules.

A lightweight, zero-dependency library that enhances Redux Toolkit's state management by adding seamless, persistent storage.

The Project

rtk-persist was born from our daily experiences building modern web and mobile applications at Fancy Pixel. We needed a simple, powerful way to add state persistence to our Redux Toolkit applications without adding heavy dependencies or complex configurations. The result is a lightweight, zero-dependency library that seamlessly integrates with your existing workflow.

The library works by wrapping standard Redux Toolkit functions, adding persistence logic without changing the way you write your reducers or actions. This makes it incredibly easy to add or remove persistence, often by just changing an import statement.

With the release of version 2.0, we've introduced asynchronous rehydration, which ensures your application only renders after the state has been fully restored from storage, preventing any UI flicker. We've also added a dedicated module for seamless integration with React applications.

Key Features

  • Effortless Persistence: Persist any Redux Toolkit slice or reducer with minimal configuration.
  • Asynchronous Rehydration: Store creation is now asynchronous, ensuring that your app only renders after the state has been fully rehydrated.
  • Seamless Integration: Designed as a drop-in replacement for RTK functions. Adding or removing persistence is as simple as changing an import.
  • React Redux Integration: Comes with a usePersistedStore hook for easy integration with React applications.
  • Flexible API: Choose between a createPersistedSlice utility or a createPersistedReducer builder syntax.
  • Nested State Support: Easily persist slices or reducers that are deeply nested within your root state using a simple nestedPath option.
  • Custom Serialization: Use onPersist and onRehydrate to transform your state before saving and after loading.
  • Storage Agnostic: Works with any storage provider that implements a simple getItem, setItem, and removeItem interface.
  • TypeScript Support: Fully typed to ensure a great developer experience with path validation.
  • Minimal Footprint: Extremely lightweight with a production size under 15 KB.

Tech Stack

Typescript

If you want to turn your idea into
a concrete solution, contact us!