Files
url_tracker_tool/node_modules/use-sidecar/dist/es2015/hook.js
Andrei 58f8093689 Rebrand from 'Redirect Intelligence v2' to 'URL Tracker Tool V2' throughout UI
- Updated all component headers and documentation
- Changed navbar and footer branding
- Updated homepage hero badge
- Modified page title in index.html
- Simplified footer text to 'Built with ❤️'
- Consistent V2 capitalization across all references
2025-08-19 19:12:23 +00:00

42 lines
1.7 KiB
JavaScript

import { useState, useEffect } from 'react';
import { env } from './env';
var cache = new WeakMap();
var NO_OPTIONS = {};
export function useSidecar(importer, effect) {
var options = (effect && effect.options) || NO_OPTIONS;
if (env.isNode && !options.ssr) {
return [null, null];
}
// eslint-disable-next-line react-hooks/rules-of-hooks
return useRealSidecar(importer, effect);
}
function useRealSidecar(importer, effect) {
var options = (effect && effect.options) || NO_OPTIONS;
var couldUseCache = env.forceCache || (env.isNode && !!options.ssr) || !options.async;
var _a = useState(couldUseCache ? function () { return cache.get(importer); } : undefined), Car = _a[0], setCar = _a[1];
var _b = useState(null), error = _b[0], setError = _b[1];
useEffect(function () {
if (!Car) {
importer().then(function (car) {
var resolved = effect ? effect.read() : car.default || car;
if (!resolved) {
console.error('Sidecar error: with importer', importer);
var error_1;
if (effect) {
console.error('Sidecar error: with medium', effect);
error_1 = new Error('Sidecar medium was not found');
}
else {
error_1 = new Error('Sidecar was not found in exports');
}
setError(function () { return error_1; });
throw error_1;
}
cache.set(importer, resolved);
setCar(function () { return resolved; });
}, function (e) { return setError(function () { return e; }); });
}
}, []);
return [Car, error];
}