Platform docs
Auth, users, webhooks & more
Info:
This is beta documentation for Stream Video React Native SDK v2. For the latest stable version, see the latest version (v1).

React Compiler

Import call state hooks directly for React Compiler compatibility.

React Compiler enforces stricter hook constraints for build-time optimization. eslint-plugin-react-compiler reports incompatible patterns.

Problem

When using React Compiler, calling useCallStateHooks() inside a component violates React Compiler's static analysis requirements. These requirements are enforced during development by ESLint, which reports the error shown below.

ESLint: Hooks must be the same function on every render, but this value may change over time to a different function.
See https://react.dev/reference/rules/react-calls-components-and-hooks#dont-dynamically-use-hooks (react-compiler/react-compiler)

Why this breaks with React Compiler

useCallStateHooks() is not a React hook. It is a factory function that returns hooks.

Calling it inside a component creates hook function references during render. Even if those references are stable, React Compiler cannot verify that at compile time. Because hook functions must be statically known and identical on every render, this pattern is rejected.

Solution

Every call state hook is exported directly from the SDK. Import the hooks you need by name and remove the useCallStateHooks() call. The hook names, arguments and return values stay the same.

Before / After

Before:

import { useCallStateHooks } from "@stream-io/video-react-native-sdk";
import { View, Text } from "react-native";

const MyComponent = () => {
  const { useCallCallingState, useParticipants } = useCallStateHooks();
  const callingState = useCallCallingState();
  const participants = useParticipants();

  return (
    <View>
      <Text>State: {callingState}</Text>
      <Text>Participants: {participants.length}</Text>
    </View>
  );
};

After:

import {
  useCallCallingState,
  useParticipants,
} from "@stream-io/video-react-native-sdk";
import { View, Text } from "react-native";

const MyComponent = () => {
  const callingState = useCallCallingState();
  const participants = useParticipants();

  return (
    <View>
      <Text>State: {callingState}</Text>
      <Text>Participants: {participants.length}</Text>
    </View>
  );
};

Alternative: call useCallStateHooks() at module scope

If you prefer to keep useCallStateHooks(), call it once at module scope, then destructure the hooks you need. Use those hooks normally inside your components.

  1. Alias the import to avoid naming confusion (import as getCallStateHooks)
  2. Call the factory once at module scope
  3. Destructure hooks at the top level
  4. Use the hooks normally inside components
import { useCallStateHooks as getCallStateHooks } from "@stream-io/video-react-native-sdk";
import { View, Text } from "react-native";

const { useCallCallingState, useParticipants } = getCallStateHooks();

const MyComponent = () => {
  const callingState = useCallCallingState();
  const participants = useParticipants();

  return (
    <View>
      <Text>State: {callingState}</Text>
      <Text>Participants: {participants.length}</Text>
    </View>
  );
};

What not to do

Do not call the factory inside the component:

import { useCallStateHooks as getCallStateHooks } from "@stream-io/video-react-native-sdk";

const MyComponent = () => {
  const hooks = getCallStateHooks(); // still dynamic, still triggers the error
  const { useCallCallingState } = hooks;
  // ...
};

Why alias to getCallStateHooks

Aliasing useCallStateHooks to getCallStateHooks is required. If you call useCallStateHooks() at module scope without aliasing, ESLint will error because functions starting with use are treated as hooks and cannot be called outside of components. The alias makes it clear that you're calling a factory function at module scope, not using a hook inside a component.

Automated migration with codemod

The @stream-io/video-codemod package transforms your codebase automatically. Its use-call-state-hooks codemod applies the module scope pattern described above.

Usage

Run the use-call-state-hooks codemod on your codebase:

npx @stream-io/video-codemod use-call-state-hooks ./src \
  --extensions=ts,tsx \
  --parser=tsx \
  --run-prettier # optional, runs prettier on the transformed files