Apollo Client (Web)
IntroductionWhy Apollo Client?Get started
Core concepts
Caching
Pagination
Local State
Development & Testing
Performance
Integrations
Networking
API Reference
ChangelogMigrating to Apollo Client 4.0Versioning Policy

useReactiveVar

Apollo Client API reference


Reads the value of a reactive variable and re-renders the containing component whenever that variable's value changes. This enables a reactive variable to trigger changes without relying on the useQuery hook.

Example

JavaScript
1 import { makeVar } from "@apollo/client";
2 import { useReactiveVar } from "@apollo/client/react";
3 export const cartItemsVar = makeVar([]);
4
5 export function Cart() {
6   const cartItems = useReactiveVar(cartItemsVar);
7   // ...
8 }

Signature

TypeScript
1useReactiveVar<T>(
2  rv: ReactiveVar<T>
3): T
(src/react/hooks/useReactiveVar.ts)

Parameters

Name / Type
Description
rv
ReactiveVar<T>

A reactive variable.

Show/hide child attributes

Result

The current value of the reactive variable.
T