Last active
November 19, 2021 16:32
-
-
Save alex-boom/f284c02782fb2b97aa07238c8f4bbec4 to your computer and use it in GitHub Desktop.
makeVar Apollo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Инициализация переменной в корне(если инитить в компоненте или в любой обертке функции работать не будет) | |
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