24 lines
597 B
TypeScript
24 lines
597 B
TypeScript
// Implementation taken from remix-utils: https://github.com/sergiodxa/remix-utils
|
|
|
|
import { useSyncExternalStore } from "react";
|
|
|
|
function subscribe() {
|
|
return () => {};
|
|
}
|
|
|
|
/**
|
|
* Returns true once React hydration has completed on the client.
|
|
* Use this to disable interactive elements during SSR when event handlers aren't attached.
|
|
*
|
|
* @example
|
|
* const isHydrated = useHydrated();
|
|
* return <button disabled={!isHydrated} onClick={handler}>Submit</button>;
|
|
*/
|
|
export function useHydrated(): boolean {
|
|
return useSyncExternalStore(
|
|
subscribe,
|
|
() => true,
|
|
() => false,
|
|
);
|
|
}
|