Skip to content
LogoLogo

Remote.useState

React hook that subscribes to the Remote context's Zustand store. Re-renders whenever the selected slice changes.

Usage

import { Remote } from 'accounts/react'
 
import { remote } from '../lib/config.js'
 
// Subscribe to the full state.
const state = Remote.useState(remote)
 
// Or subscribe to a slice via a selector.
const ready = Remote.useState(remote, (s) => s.ready)

Parameters

remote

  • Type: Remote.Remote
  • Required

The remote context returned from Remote.create.

import { Remote } from 'accounts/react'
 
import { remote } from '../lib/config.js'
 
const state = Remote.useState(remote) 

selector

  • Type: (state: Remote.State) => selected
  • Optional

Function that picks a slice from the store's state. The component only re-renders when the selected value changes (using Object.is equality).

import { Remote } from 'accounts/react'
 
import { remote } from '../lib/config.js'
 
const ready = Remote.useState(remote, (s) => s.ready) 
const mode = Remote.useState(remote, (s) => s.mode) 

Returns

The full Remote.State when no selector is provided, otherwise the selector's return value:

type State = {
  /** Whether the dialog is rendered in an iframe or popup. */
  mode: 'iframe' | 'popup' | undefined
  /** Trusted host origin from MessageEvent. */
  origin: string | undefined
  /** Whether the dialog is ready to display content. */
  ready: boolean
  /** Queued RPC requests received from the host. */
  requests: Remote.State['requests']
}