Skip to content

Instantly share code, notes, and snippets.

@alex-boom
Last active November 19, 2021 16:32
Show Gist options
  • Save alex-boom/f284c02782fb2b97aa07238c8f4bbec4 to your computer and use it in GitHub Desktop.
Save alex-boom/f284c02782fb2b97aa07238c8f4bbec4 to your computer and use it in GitHub Desktop.
makeVar Apollo
// Инициализация переменной в корне(если инитить в компоненте или в любой обертке функции работать не будет)
export const translationInterface = makeVar({});
/****************************/
// в компоненте получаем данные из query и кладем в рективную переменную
import { translationInterface } from "../../../graphql/cache";
// SET dataQueryTranslation to reactive variable
useEffect(() => {
translationInterface(dataQueryTranslation)
}, [ dataQueryTranslation ]);
/****************************/
// в компоненте где необходимо получить данные из рекативной переменной вызываем хук Apollo useReactiveVar() и тут же получаем данные
import { translationInterface } from "../../../graphql/cache";
import { useReactiveVar } from "@apollo/client";
// GET dataQueryTranslation arr from reactive variable
const translationReactiveVar = useReactiveVar(translationInterface)?.translations?.data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment