Advanced 🏄‍♀️
Persistence

Persistence

ShimmerShard allows you to persist data without worries about losing data. We'll be keeping the all data that you want. Just keep it there!

Create a persistence shard

The way to create a persistence shard is just like a normal shard but we use persist instead of shard.

import { persist } from "shimmershards";
const examplePersistShard = persist({
  initialValue: 0,
  // localStorage's key
  key: "key",
  // optional
  fallback: 2,
});

To consume the persistance shard you need to use usePersistShard instead ofuseShard.

import { persist, usePersistShard } from "shimmershards";
 
const examplePersistShard = persist({
  initialValue: 0,
  // localStorage's key
  key: "key",
  // optional
  fallback: 2,
});
 
const Component = () => {
  const [counter, setCounter] = usePersistShard(examplePersistShard);
  return <div>...</div>;
};

State sharing still uses the same approach as shard. Persistence shard is compatible with Cluster also.

Caveats

The persistence shard will not be able to be Scope.