How to use the react-apollo-hooks.useApolloClient function in react-apollo-hooks

To help you get started, we’ve selected a few react-apollo-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alltogethernow / web / src / components / Auth / index.js View on Github external
const Auth = props => {
  const [status, setStatus] = useState(null)
  const [loading, setLoading] = useState(false)
  const login = useMutation(LOGIN)
  const { enqueueSnackbar } = useSnackbar()
  const client = useApolloClient()

  const handleLogin = async () => {
    setLoading(true)
    try {
      const urlParams = new URLSearchParams(window.location.search)
      const code = urlParams.get('code')
      const state = urlParams.get('state')
      const { data, errors } = await login({ variables: { code, state } })
      if (errors) {
        console.error('[Error logging in]', errors)
        enqueueSnackbar('Error logging in', { variant: 'error' })
        setStatus(false)
      }
      if (data && data.login && data.login.token) {
        const jwt = data.login.token
        enqueueSnackbar(`Welcome to Together`)
github alltogethernow / web / src / components / AppBar / SettingsMenu.js View on Github external
const SettingsMenu = ({ classes }) => {
  const client = useApolloClient()
  const [anchorEl, setAnchorEl] = useState(null)
  const [localState, setLocalState] = useLocalState()
  const { user } = useUser()
  const channel = useCurrentChannel()

  const logout = e => {
    window.localStorage.removeItem('token')
    client.resetStore()
    window.location.href = '/'
  }

  return (
    
      
        {user && user.photo ? (
github mgm-interns / team-radio / client / src / Components / Header / Menu / Menu.tsx View on Github external
export const Menu: React.FunctionComponent = props => {
  const classes = useStyles();

  const themeContext = React.useContext(ThemeContext);

  const client = useApolloClient();

  const {
    anchorEl,
    onClose,
    history: { push },
    match
  } = props;

  return (
     onClose()}
github mgm-interns / team-radio / client / src / Pages / LoginPage / LoginPage.tsx View on Github external
const LoginPage: React.FunctionComponent = props => {
  const classes = useStyles();

  const [username, setUsername] = React.useState('');
  const [password, setPassword] = React.useState('');
  const [errorText, setErrorText] = React.useState('');
  const [loading, loadingAction] = useToggle(false);

  const login = LoginMutation.useMutation();
  const client = useApolloClient();

  const onSubmit = React.useCallback(async () => {
    setErrorText('');
    loadingAction.toggleOn();
    if (!username && !password) return;
    try {
      const variables: LoginMutation.Variables = { password };

      if (username && username.includes('@')) {
        variables.email = username;
      } else {
        variables.username = username;
      }

      const response = await login({ variables });
      loadingAction.toggleOff();
github neinteractiveliterature / intercode / app / javascript / CmsAdmin / CmsLayoutsAdmin / EditCmsLayout.jsx View on Github external
function EditCmsLayout({ match, history }) {
  const { data, error } = useQuerySuspended(CmsLayoutsAdminQuery);
  const initialLayout = error
    ? null
    : data.cmsLayouts.find((p) => match.params.id === p.id.toString());
  const [layout, dispatch] = useReducer(layoutReducer, initialLayout);
  const [updateMutate] = useMutation(UpdateLayout);
  const [updateLayout, updateError, updateInProgress] = useAsyncFunction(updateMutate);
  const apolloClient = useApolloClient();

  usePageTitle(useValueUnless(() => `Editing “${initialLayout.name}”`, error));

  if (error) {
    return ;
  }

  const formSubmitted = async (event) => {
    event.preventDefault();
    await updateLayout({
      variables: {
        id: initialLayout.id,
        cmsLayout: buildLayoutInput(layout),
      },
    });
    await apolloClient.resetStore();

react-apollo-hooks

Use [Apollo Client](https://github.com/apollographql/apollo-client) as React [hooks](https://reactjs.org/docs/hooks-intro.html).

MIT
Latest version published 5 years ago

Package Health Score

53 / 100
Full package analysis

Similar packages