use-async-effekt-hooks
Version:
React hooks for async effects and memoization with proper dependency tracking and linting support
36 lines (35 loc) • 1.24 kB
JavaScript
import React from "react";
import semver from "semver";
// types not present, since @testing-library/react-hooks and @testing-library/react are not stable types
// dependencies due to matrix testing and dynamic installation
var renderHook;
var act;
var waitFor;
// React 18+ uses @testing-library/react for renderHook
// React 16/17 use @testing-library/react-hooks
if (semver.gte(React.version, "18.0.0")) {
try {
var testingLibReact = require("@testing-library/react");
renderHook = testingLibReact.renderHook;
act = testingLibReact.act;
waitFor = testingLibReact.waitFor;
}
catch (error) {
console.error("Could not import @testing-library/react:", error);
throw error;
}
}
else {
try {
var testingLibHooks = require("@testing-library/react-hooks");
var testingLibReact = require("@testing-library/react");
renderHook = testingLibHooks.renderHook;
act = testingLibHooks.act;
waitFor = testingLibReact.waitFor; // waitFor is still in @testing-library/react
}
catch (error) {
console.error("Could not import @testing-library/react-hooks:", error);
throw error;
}
}
export { renderHook, act, waitFor };