@utilityjs/use-is-server-handoff-complete
v1.0.0
Published
A React hook that returns `true` if the SSR handoff completes.
Downloads
5
Maintainers
Readme
A React hook that returns true
if the SSR handoff completes.
npm i @utilityjs/use-is-server-handoff-complete | yarn add @utilityjs/use-is-server-handoff-complete
Usage
import useIsServerHandoffComplete from "@utilityjs/use-is-server-handoff-complete";
import * as React from "react";
let __ID__ = 0;
const useDeterministicId = (inputId?: string) => {
const handoffCompletes = useIsServerHandoffComplete();
const [id, setId] = React.useState<string | null>(
inputId ?? handoffCompletes ? String(__ID__++) : null
);
React.useEffect(() => {
if (id != null) return;
setId(__ID__++);
}, [id]);
return id;
};
API
useIsServerHandoffComplete()
declare const useIsServerHandoffComplete: () => boolean;