# ngrx-rehydrate

> Persists parts of the state to localStorage and automatically load them as initial state after refresh/revisit of the page.

Latest version **1.0.0** (published 2024-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngrx-rehydrate
pnpm add ngrx-rehydrate
yarn add ngrx-rehydrate
bun add ngrx-rehydrate
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-06-07 |
| First published | 2022-07-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ZsoltD |
| Maintainers | amdor |
| Keywords | rehydration, ngrx, createreducer |

## Links

- npm: https://www.npmjs.com/package/ngrx-rehydrate
- Repository: https://github.com/amdor/ngrx-rehydrate
- Homepage: hhttps://github.com/amdor/ngrx-rehydrate#readme
- Issues: https://github.com/amdor/ngrx-rehydrate/issues
- npm.io page: https://npm.io/package/ngrx-rehydrate

## Dependencies (3)

- [18](https://npm.io/package/18.md) ^0.0.0
- [typescript](https://npm.io/package/typescript.md) ^5.4.5
- [@ngrx/store](https://npm.io/package/@ngrx/store.md) ^18.0.0-beta.1

## Recent versions

- 1.0.0 (latest) — 2024-06-07
- 0.0.2 — 2022-07-05
- 0.0.1 — 2022-07-05

## README

# ngrx-rehydrate

Persists parts of the state to localStorage and automatically load them as initial state after refresh/revisit of the page.

## Usage

```typescript
export const exampleReducer = createRehydrateReducer(
    { key: 'key1' },
    INITIAL_STATE,
    on(setAction, (state, { flag }) => ({ ...state, flag })),
);
```

```typescript
function createRehydrateReducer<S, A extends Action = Action, R extends ActionReducer<S, A> = ActionReducer<S, A>>(
    config: RehydrateRecucerConfig,
    initialState: S,
    ...ons: ReducerTypes<S, ActionCreator[]>[]
): R 
```
where

| Param        | Description                                           |
| ------------ | ----------------------------------------------------- |
| config       | RehydrateRecucerConfig object for rehydration options |
| initialState | same as with the default `createReducer` function     |
| ons          | same as with the default `createReducer` function     |

## Refs

For more usage examples see the tests https://github.com/amdor/ngrx-rehydrate/blob/main/test/create-rehydrate-reducer.spec.ts

More on rehydration: https://medium.com/betsson-group/the-easiest-way-to-keep-ngrx-state-after-refresh-rehydrate-it-from-localstorage-8cd23b547aac

## Types

#### RehydrateRecucerConfig

| Property | Description                                                                                                               |
| -------- | ------------------------------------------------------------------------------------------------------------------------- |
| key      | the key to store the substate by. must be unique otherwise 2 state slices would try saving to the same `localStorage` key |

---
_Source: https://npm.io/package/ngrx-rehydrate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
