# useSelectedChannelState

A low-level primitive that subscribes to channel events and returns a value derived from the channel via a selector. It is built on React's `useSyncExternalStore`, and most of the other channel-state hooks (e.g. [`useChannelName`](/chat/docs/sdk/react-native/hooks/channel-state/use-channel-name/), [`useChannelImage`](/chat/docs/sdk/react-native/hooks/channel-state/use-channel-image/), [`useChannelOwnCapabilities`](/chat/docs/sdk/react-native/hooks/channel-state/use-channel-own-capabilities/)) delegate to it.

This is an advanced building block. Prefer the purpose-built hooks above for common cases, and reach for this hook only when you need to read a piece of channel state that does not yet have a dedicated hook.

## Best Practices

- Keep the `selector` referentially stable (define it at module scope or memoize it) to avoid re-subscribing on every render.
- Keep `stateChangeEventKeys` referentially stable for the same reason; it defaults to `['all']`, which re-renders on every channel event — narrow it to the specific events you care about for better performance.
- Return primitive or shallowly-stable values from the selector so React can bail out of unnecessary re-renders.
- Handle `undefined` — the hook returns `undefined` when no channel is provided.

## Usage

```tsx
import { useSelectedChannelState } from "stream-chat-react-native";

const memberCount = useSelectedChannelState({
  channel,
  selector: (channel) => channel.data?.member_count ?? 0,
  stateChangeEventKeys: ["channel.updated"],
});
```

## Parameters

The hook takes a single options object:

| Name                 | Type                      | Required | Description                                                         |
| -------------------- | ------------------------- | -------- | ------------------------------------------------------------------- |
| channel              | `Channel`                 | No       | Channel to subscribe to. The hook returns `undefined` when omitted. |
| selector             | `(channel: Channel) => O` | Yes      | Derives the value to return from the channel.                       |
| stateChangeEventKeys | `EventTypes[]`            | No       | Channel events that trigger re-evaluation. Defaults to `['all']`.   |

## Returns

| Type               | Description                                                              |
| ------------------ | ------------------------------------------------------------------------ |
| `O` \| `undefined` | The value returned by `selector`, or `undefined` when no channel is set. |


---

This page was last updated at 2026-06-30T12:00:28.165Z.

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/sdk/react-native/hooks/channel-state/use-selected-channel-state/](https://getstream.io/chat/docs/sdk/react-native/hooks/channel-state/use-selected-channel-state/).