mirror of
https://github.com/dergigi/boris.git
synced 2025-12-28 20:14:36 +01:00
- 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.
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import type { MutableRefObject, RefObject } from "react";
|
|
import { BehaviorSubject } from "rxjs";
|
|
import { useState } from "react";
|
|
|
|
/**
|
|
* Returns a mutable ref object and a BehaviorSubject.
|
|
*
|
|
* Whenever ref.current is changed, the BehaviorSubject will emit the new value.
|
|
*
|
|
* @param initialValue The initial value of the BehaviorSubject.
|
|
*/
|
|
export function useObservableRef<TValue>(
|
|
initialValue: TValue
|
|
): [MutableRefObject<TValue>, BehaviorSubject<TValue>];
|
|
/**
|
|
* Returns a ref object and a BehaviorSubject.
|
|
*
|
|
* Whenever ref.current is changed, the BehaviorSubject will emit the new value.
|
|
*
|
|
* @param initialValue The initial value of the BehaviorSubject.
|
|
*/
|
|
export function useObservableRef<TValue>(
|
|
initialValue: TValue | null
|
|
): [RefObject<TValue>, BehaviorSubject<TValue>];
|
|
/**
|
|
* Returns a mutable ref object and a BehaviorSubject.
|
|
*
|
|
* Whenever ref.current is changed, the BehaviorSubject will emit the new value.
|
|
*
|
|
* @param initialValue A optional initial value of the BehaviorSubject.
|
|
*/
|
|
export function useObservableRef<TValue = undefined>(
|
|
initialValue?: TValue
|
|
): [MutableRefObject<TValue | undefined>, BehaviorSubject<TValue | undefined>];
|
|
export function useObservableRef<TValue>(
|
|
initialValue?: TValue
|
|
): [MutableRefObject<TValue | undefined>, BehaviorSubject<TValue | undefined>] {
|
|
const [value$] = useState(() => new BehaviorSubject(initialValue));
|
|
const [ref] = useState<MutableRefObject<TValue | undefined>>(() => ({
|
|
get current(): TValue | undefined {
|
|
return value$.value;
|
|
},
|
|
set current(value: TValue | undefined) {
|
|
value$.next(value);
|
|
},
|
|
}));
|
|
return [ref, value$];
|
|
}
|