Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add array examples to reactive variable documentation #10235

Merged
merged 3 commits into from
Nov 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions docs/source/local-state/reactive-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ To modify the value of your reactive variable, call the function returned by `ma

```js
const cartItemsVar = makeVar([]);
const cartItemIds = [100, 101, 102];

cartItemsVar([100, 101, 102]);
cartItemsVar(cartItemIds);

// Output: [100, 101, 102]
console.log(cartItemsVar());

cartItemsVar([456]);
// Don't mutate an existing object or array.
// cartItemIds.push(456) will not trigger an update.
// Instead, pass a new copy:
cartItemsVar([...cartItemIds, 456]);

// Output: [456]
// Output: [100, 101, 102, 456]
console.log(cartItemsVar());
```

Expand Down Expand Up @@ -77,4 +81,4 @@ export function Cart() {

## Example application

[This example to-do list application](https://github.com/apollographql/ac3-state-management-examples/tree/master/apollo-local-state) uses reactive variables to track both the current list of to-do items and the filter that determines which items to display. See [`cache.tsx`](https://github.com/apollographql/ac3-state-management-examples/blob/master/apollo-local-state/src/cache.tsx) in particular.
[This example to-do list application](https://github.com/apollographql/ac3-state-management-examples/tree/master/apollo-local-state) uses reactive variables to track both the current list of to-do items and the filter that determines which items to display. See [`cache.tsx`](https://github.com/apollographql/ac3-state-management-examples/blob/master/apollo-local-state/src/cache.tsx) in particular.