refactor: improve generic typing for unlock and overhaul example app UI styling
This commit is contained in:
@@ -24,11 +24,10 @@ export function useCryptoLocker<T = unknown>(dependencies: Record<string, any> =
|
||||
* @param password The AES password.
|
||||
*/
|
||||
const unlock = useCallback(
|
||||
async (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
fetchData: () => Promise<any>,
|
||||
async <M, R = M extends { default: infer D } ? D : M>(
|
||||
fetchData: () => Promise<M>,
|
||||
password: string
|
||||
): Promise<T> => {
|
||||
): Promise<R> => {
|
||||
setStatus("loading");
|
||||
setError(null);
|
||||
|
||||
@@ -75,9 +74,9 @@ export function useCryptoLocker<T = unknown>(dependencies: Record<string, any> =
|
||||
);
|
||||
fn(requireFn, exportsObj, moduleObj, React);
|
||||
|
||||
const parsed = (moduleObj.exports.default ?? moduleObj.exports) as T;
|
||||
const parsed = (moduleObj.exports.default ?? moduleObj.exports) as R;
|
||||
|
||||
setDecryptedData(() => parsed);
|
||||
setDecryptedData(() => parsed as unknown as T);
|
||||
setStatus("success");
|
||||
return parsed;
|
||||
} catch (err: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user