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, useReactiveVar } from "@apollo/client";
2 export const cartItemsVar = makeVar([]);
3
4 export function Cart() {
5   const cartItems = useReactiveVar(cartItemsVar);
6   // ...
7 }

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
Feedback

Edit on GitHub

Ask Community