Acquire a tracked, ref-counted reference from the global context.
The returned ServiceRef must be .release()'d when the component/module is done with the service. This ensures the SDK can track how many consumers hold a service and detect leaks.
.release()
The service type.
The service token.
A new ServiceRef<T>.
ServiceRef<T>
If no global context is set.
If the token is not registered.
1.2.0
// In a React component:useEffect(() => { const rpcRef = useSharedRef(Tokens.RPC); rpcRef.current.getBalance(pubkey).then(setBalance); return () => rpcRef.release(); // cleanup on unmount}, []); Copy
// In a React component:useEffect(() => { const rpcRef = useSharedRef(Tokens.RPC); rpcRef.current.getBalance(pubkey).then(setBalance); return () => rpcRef.release(); // cleanup on unmount}, []);
Acquire a tracked, ref-counted reference from the global context.
The returned ServiceRef must be
.release()'d when the component/module is done with the service. This ensures the SDK can track how many consumers hold a service and detect leaks.