> For the complete documentation index, see [llms.txt](https://bret-maxime.gitbook.io/reactjrx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bret-maxime.gitbook.io/reactjrx/utils/react/useconstant.md).

# useConstant

Creates a value on the first render and returns that same value on every render after it.

### Usage

```tsx
import { useConstant } from "reactjrx"
import { BehaviorSubject } from "rxjs"

const Counter = () => {
  const count$ = useConstant(() => new BehaviorSubject(0))

  // ...
}
```

The value lives in a ref, so it is never recomputed. React can drop a `useMemo` value and compute it again, which would create a second subject.

### Reference

```typescript
function useConstant<T>(fn: () => T): T
```
