> ## Documentation Index
> Fetch the complete documentation index at: https://docs.livepeer.org/llms.txt
> Use this file to discover all available pages before exploring further.

# useCreateStream

> React Hook for creating a new stream.

Hook for creating a new
[Stream](https://github.com/livepeer/react/blob/main/packages/core/src/types/provider.ts).

## Usage

<Tabs>
  <Tab title="React">
    ```tsx theme={"theme":{"light":"github-light","dark":"dark-plus"}}
    import { useCreateStream } from '@livepeer/react';
    ```
  </Tab>

  <Tab title="React Native">
    ```tsx theme={"theme":{"light":"github-light","dark":"dark-plus"}}
    import { useCreateStream } from '@livepeer/react-native';
    ```
  </Tab>
</Tabs>

<Warning>
  The stream ID should only be passed to users who are allowed to modify the
  stream. **Ensure viewers are only provided with the `playbackId`,** which is a
  limited identifier that provides only the ability to stream media using the
  [`Player`](/sdks/react/Player).
</Warning>

The following example shows how a stream can be created.

```tsx theme={"theme":{"light":"github-light","dark":"dark-plus"}}
const streamName = `New Stream`;

function SomeComponent() {
  const {
    mutate: createStream,
    data: stream,
    status,
  } = useCreateStream({ name: streamName });

  return (
    <div>
      <button
        disabled={status === "loading" || !createStream}
        onClick={() => createStream?.()}
      >
        Create Stream
      </button>
      {stream && <div>Stream Key: {stream.streamKey}</div>}
    </div>
  );
}
```

## Return Value

The return value is partially based on
[Tanstack Query](https://tanstack.com/query/v4/docs/reference/useMutation), with
some return types aggregated for simplicity.

```tsx theme={"theme":{"light":"github-light","dark":"dark-plus"}}
{
  data?: Stream,
  error?: Error,
  isError: boolean,
  isIdle: boolean,
  isLoading: boolean,
  isSuccess: boolean,
  status: 'idle' | 'loading' | 'success' | 'error',
  mutate: () => void,
  mutateAsync: () => Promise<Stream>,
  variables?: CreateStreamArgs
}
```

## Configuration

### name

The name for the new stream. Required to create a stream.

```tsx theme={"theme":{"light":"github-light","dark":"dark-plus"}}
function SomeComponent() {
  const { mutate: createStream } = useCreateStream({
    name: "My new stream",
  });
}
```

### profiles

Transcoding profiles to use for the stream for ABR playback. When this is not
defined, the `defaultTranscodingProfiles` are used (720p, 480p, and 360p).

### record

Whether to create recordings of the stream sessions. Defaults to `false`.

### multistream

The configuration for multistreaming (AKA "restream" or "simulcast") - allows
configuration of targets where this stream should be simultaneously streamed to.

### playbackPolicy

Configuration for stream playback access-control policy. Defaults to `public`.

```tsx theme={"theme":{"light":"github-light","dark":"dark-plus"}}
type PlaybackPolicy = {
  /**
   * The type of playback policy to apply. `jwt` requires a signed JWT for
   * playback. `webhook` requires that a webhook is configured and passed during the
   * creation of the asset. `public` indicates no
   * access control will be applied (anyone with the `playbackId` can
   * view without a JWT or webhook).
   */
  type: "webhook" | "jwt" | "public";
};

type WebhookPlaybackPolicy<TContext extends object> = PlaybackPolicy & {
  type: "webhook";
  /** The ID of the webhook which has already been created. */
  webhookId: string;
  /** The context which is passed to the webhook when it is called on playback. */
  webhookContext: TContext;
};
```

### mutationConfig

The `mutationConfig` parameter allows for any
[Tanstack Query](https://tanstack.com/query/v4/docs/reference/useMutation)
`useMutation` options, such as `cacheTime` or `retry`. These override any
configs passed by default by the internal hook.

```tsx {4} theme={"theme":{"light":"github-light","dark":"dark-plus"}}
function SomeComponent() {
  const { mutate: createStream } = useCreateStream({
    name: "My new stream",
    mutationConfig: { retry: 3 },
  });
}
```
