Created
October 20, 2021 20:48
-
-
Save arv/c8301854c8b7cc03ee8ac76f67892944 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from "react"; | |
import { MutatorDefs, Replicache, ReplicacheOptions } from "replicache"; | |
export function useReplicache<MD extends MutatorDefs>( | |
opts: ReplicacheOptions<MD> | |
): Replicache<MD> | null { | |
const [rep, setRep] = useState<Replicache<MD> | null>(null); | |
useEffect(() => { | |
const r = new Replicache(opts); | |
setRep(r); | |
return () => { | |
r.close(); | |
}; | |
}, [opts]); | |
return rep; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment