Function useBlocker

  • Block an async flow and unblock it from an external context.

    Returns [isBlocked: boolean, block: (() => Promise<void>), unblock: (() => void)]

  • Block an async flow and unblock it from an external context.

    Type Parameters

    • T

      The type of value that can be passed to unblock to resolve the Promise returned by block.

    Returns [isBlocked: boolean, block: (() => Promise<T>), unblock: ((result: T) => void)]

    const [isBlocked, block, unblock] = useBlocker<string>();

    useEffect(() => {
    // Returns a Promise that is resolved with the value passed to unblock(value)
    block(); // → Promise<string>

    // Unblocks the blocker with given value
    unblock('Hello');
    }, []);