Files
boris/node_modules/observable-hooks/src/use-render-throw.ts
Gigi 5d53a827e0 feat: initialize markr nostr bookmark client
- Add project structure with TypeScript, React, and Vite
- Implement nostr authentication using browser extension (NIP-07)
- Add NIP-51 compliant bookmark fetching and display
- Create minimal UI with login and bookmark components
- Integrate applesauce-core and applesauce-react libraries
- Add responsive styling with dark/light mode support
- Include comprehensive README with setup instructions

This is a minimal MVP for a nostr bookmark client that allows users to
view their bookmarks according to NIP-51 specification.
2025-10-02 07:17:07 +02:00

47 lines
1.2 KiB
TypeScript

import { useRef } from "react";
import { Observable, NEVER } from "rxjs";
import { catchError, switchMap } from "rxjs/operators";
import { useForceUpdate } from "./helpers";
import { useObservable } from "./use-observable";
/**
* Enhance an Observable by making errors catch-able to ErrorBoundary.
*
* It catches Observable error and re-throw it as React render error.
*
* @template TInput Input value within Observable.
*
* @param input$ Input Observable.
* @returns Observable with the same input type
*/
export function useRenderThrow<TInput>(
input$: Observable<TInput>
): Observable<TInput> {
const forceUpdate = useForceUpdate();
const errorRef = useRef<Error | null>();
const output$ = useObservable(
inputs$ =>
inputs$.pipe(
switchMap(([input$]) => {
errorRef.current = null;
return input$.pipe(
catchError(error => {
errorRef.current = error;
forceUpdate();
return NEVER;
})
);
})
),
[input$]
);
if (errorRef.current) {
// Let error boundary catch the error
throw errorRef.current;
}
return output$;
}