"use strict";
// This is a helper required for React 19 testing.
// There are currently multiple directions this could play out in RTL and none of
// them has been released yet, so we are inlining this helper for now.
// See https://github.com/testing-library/react-testing-library/pull/1214
// and https://github.com/testing-library/react-testing-library/pull/1365
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderHookAsync = renderHookAsync;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const ReactDOM = tslib_1.__importStar(require("react-dom"));
const renderAsync_js_1 = require("./renderAsync.cjs");
async function renderHookAsync(renderCallback, options = {}) {
    const { initialProps, ...renderOptions } = options;
    // @ts-expect-error
    if (renderOptions.legacyRoot && typeof ReactDOM.render !== "function") {
        const error = new Error("`legacyRoot: true` is not supported in this version of React. " +
            "If your app runs React 19 or later, you should remove this flag. " +
            "If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.");
        Error.captureStackTrace(error, renderHookAsync);
        throw error;
    }
    const result = React.createRef();
    function TestComponent({ renderCallbackProps, }) {
        const pendingResult = renderCallback(renderCallbackProps);
        React.useEffect(() => {
            result.current = pendingResult;
        });
        return null;
    }
    const { rerender: baseRerender, unmount } = await (0, renderAsync_js_1.renderAsync)(React.createElement(TestComponent, { renderCallbackProps: initialProps }), renderOptions);
    function rerender(rerenderCallbackProps) {
        return baseRerender(React.createElement(TestComponent, { renderCallbackProps: rerenderCallbackProps }));
    }
    return { result, rerender, unmount };
}
//# sourceMappingURL=renderHookAsync.cjs.map
