How to use the react-apollo-hooks.useMutation 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 Urigo / WhatsApp-Clone-Client-React / src / components / GroupDetailsScreen / index.tsx View on Github external
users = chat.allTimeMembers
    participants = users.slice()

    // Read-only if not owned by me
    if (ownedByMe) {
      chatNameState = useState(chat.name)
      chatPictureState = useState(chat.picture)
    } else {
      chatNameState = [chat.name, () => {}]
      chatPictureState = [chat.picture, () => {}]
    }

    const [chatName] = chatNameState
    const [chatPicture] = chatPictureState

    updateChat = useMutation<
      GroupDetailsScreenMutation.Mutation,
      GroupDetailsScreenMutation.Variables
    >(mutation, {
      variables: {
        chatId,
        name: chatName,
        picture: chatPicture,
      },
      optimisticResponse: {
        __typename: 'Mutation',
        updateChat: {
          ...chat,
          __typename: 'Chat',
          picture: chatPicture,
          name: chatName,
        },
github hasura / graphql-engine / community / sample-apps / whatsapp-clone-typescript-react / react-app / src / components / GroupDetailsScreen / index.tsx View on Github external
return user.user
    });

    // Read-only if not owned by me
    if (ownedByMe) {
      chatNameState = useState(chat[0].name)
      chatPictureState = useState(chat[0].picture)
    } else {
      chatNameState = [chat[0].name, () => {}]
      chatPictureState = [chat[0].picture, () => {}]
    }

    const [chatName] = chatNameState
    const [chatPicture] = chatPictureState

    updateChat = useMutation(updateMutation, {
      variables: {
        chatId,
        name: chatName,
        picture: chatPicture,
      },
      update: (client, { data: { update_chat } }) => {
        chat[0].picture = update_chat.returning[0].picture
        chat[0].name = update_chat.returning[0].name

        client.writeFragment({
          id: defaultDataIdFromObject(chat),
          fragment: fragments.chat,
          fragmentName: 'chat',
          data: chat,
        })
      },
github NoQuarterTeam / split / packages / web / src / lib / graphql / types.tsx View on Github external
export function use(
    baseOptions?: ReactApolloHooks.MutationHookOptions,
  ) {
    return ReactApolloHooks.useMutation(
      Document,
      baseOptions,
    )
  }
}
github neinteractiveliterature / intercode / app / javascript / useMutationCallback.js View on Github external
export default function useMutationCallback(mutation, baseOptions) {
  const [mutate] = useMutation(mutation, baseOptions);
  return mutate;
}
github neinteractiveliterature / intercode / app / javascript / MutationUtils.js View on Github external
export function useCreateMutation(mutation, {
  query, queryVariables: variables, arrayPath, newObjectPath, ...options
}) {
  const update = useCallback(
    createUpdater({
      query, variables, arrayPath, newObjectPath,
    }),
    [query, variables, arrayPath, newObjectPath],
  );
  const [mutate] = useMutation(mutation, { update, ...options });
  return mutate;
}
github penta-jelly / re-radio / client / src / graphql / index.tsx View on Github external
export function useRegisterMutation(
  baseOptions?: ReactApolloHooks.MutationHookOptions,
) {
  return ReactApolloHooks.useMutation(RegisterDocument, baseOptions);
}
github lnmunhoz / react-apollo-workshop / app-finished / src / components / Repository.js View on Github external
addStar: {
        __typename: "AddStarPayload",
        starrable: {
          __typename: "Repository",
          ...repo,
          viewerHasStarred: true,
          stargazers: {
            __typename: "StargazerConnection",
            totalCount: repo.stargazers.totalCount + 1
          }
        }
      }
    }
  });

  const removeStar = useMutation(REMOVE_STAR_MUTATION, {
    variables: {
      repoId: repo.id
    },
    optimisticResponse: {
      removeStar: {
        __typename: "RemoveStarPayload",
        starrable: {
          ...repo,
          viewerHasStarred: false,
          stargazers: {
            __typename: "StargazerConnection",
            totalCount: repo.stargazers.totalCount - 1
          },
          __typename: "Repository"
        }
      }
github lnmunhoz / react-apollo-workshop / app-finished / src / components / Repository.js View on Github external
export default function Repository({ repo }) {
  const addStar = useMutation(ADD_STAR_MUTATION, {
    variables: {
      repoId: repo.id
    },
    optimisticResponse: {
      addStar: {
        __typename: "AddStarPayload",
        starrable: {
          __typename: "Repository",
          ...repo,
          viewerHasStarred: true,
          stargazers: {
            __typename: "StargazerConnection",
            totalCount: repo.stargazers.totalCount + 1
          }
        }
      }
github nomadcoders / prismagram-frontend / src / Routes / Profile / ProfileContainer.js View on Github external
export default withRouter(({ match: { params: { username } } }) => {
  const { data, loading } = useQuery(GET_USER, { variables: { username } });
  const logOut = useMutation(LOG_OUT);
  return ;
});
github MarcinMiler / tinder-clone / packages / web / src / Pages / Discover / Components / Cards / CardsContainer.tsx View on Github external
export const CardsContainer: React.FC = () => {
    const { data, loading } = useQuery(UsersQuery)

    const like = useMutation(LikeMutation)
    const dislike = useMutation(DislikeMutation)

    if (loading) return <p>loading</p>

    return 
}

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