-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
ReactiveVar doesn't cause hook to update if updated in a separate function #7779
Comments
slight update, i added a nav link to the same page, and clicking that forces a re-render and the expected data is there |
@madmaxlax The root value that you store in the reactive variable has to change for any notifications to happen, so this code const currVal = userSettingsVar();
//update the color
currVal.favoriteColor = newColor;
//set the new value
userSettingsVar(currVal); needs to modify userSettingsVar({
...userSettingsVar(),
favoriteColor: newColor,
}); |
ah yes, that makes sense. i transferred it poorly from the 'delete todo' example in the video. thank you! |
@benjamn thank you again, may i also also ask,
vs a
|
@madmaxlax Great question! Here's the PR that allowed |
Sorry to resurrect this issue even though it was closed, but I have this issue as well although I made sure to change the root object (even by additionally using lodash's |
@benjamn btw, we've been using reactiveVars on our team for a few months now and they're AWESOME |
I too have the issue that @limekiln mentions. I have a reactive var that is encapsulated in a custom hook like this (simplified for the example): const useSelectionVar = (): [Set<string>, (newSelection?: Set<string>) => void] => {
const selection = useReactiveVar(selectionVar);
const setSelection = useCallback((newSelection = new Set()): void => {
selectionVar(newSelection);
}, []);
return [
selection,
setSelection,
];
}; I can see that calling |
Hello!
I was working with reactiveVars, following along with https://youtu.be/xASrlg9rmR4?t=957
the issue may be that I, like the video, was creating a reactiveVar in the cache, rather than just on its own. But here is what I ran into:
I have my reactive var, and I made a function to update that reactive var (like the video demonstrates with delete-todo)
i have a button that, when clicked, calls that function to update the reactive var,
and i display the value of that var with useReactiveVar
however it doesn't update
Intended outcome:
when i call the addColor function, it should update the reactiveVar, and that should in turn cause a re-render because my page refers to the value changed by it
Actual outcome:
calling addColor does seem to update the var, but that doesn't trigger a re-render on the useReactiveVar hook
How to reproduce the issue:
https://codesandbox.io/s/use-reactive-var-no-update-nh75m?file=/src/App.tsx
cacheModel.ts
MyComponent.tsx
Versions
apollo-client "latest" (yarn lock says 3.3.11)
The text was updated successfully, but these errors were encountered: