1.0.0 • Published 2 years ago

@utilityjs/use-is-server-handoff-complete v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

A React hook that returns true if the SSR handoff completes.

license npm latest package npm downloads types

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;