Skip to content

Instantly share code, notes, and snippets.

@mlg87
Created July 21, 2020 21:16
Show Gist options
  • Save mlg87/4e0e3def86e97cd79a8e2680dc424ad2 to your computer and use it in GitHub Desktop.
Save mlg87/4e0e3def86e97cd79a8e2680dc424ad2 to your computer and use it in GitHub Desktop.
Using Apollo Client for global state management code samples - src/AnotherThing/index.tsx
// ./src/AnotherThing/index.tsx
import React from "react";
import { BalloonPickerThatHasAllOfTheNeededLogicInItButForSomeReasonRequiresMeToPassAMutation } from "../Balloon/Picker";
import {
useGetSelectedBalloonLocalQuery,
useGetBalloonsQuery,
useSetSelectedBalloonLocalMutation,
} from "../types/graphql";
const AnotherThing: React.FC = () => {
useGetBalloonsQuery();
const { data: localData } = useGetSelectedBalloonLocalQuery();
const [setSelectedBalloon] = useSetSelectedBalloonLocalMutation();
return (
<>
<span>
You've selected the {localData?.selectedBalloon?.color} balloon!
</span>
<BalloonPickerThatHasAllOfTheNeededLogicInItButForSomeReasonRequiresMeToPassAMutation
onClick={setSelectedBalloon}
/>
</>
);
};
export default AnotherThing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment