首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未捕获(在promise中) TypeError: loginMutation不是一个函数

未捕获(在promise中) TypeError: loginMutation不是一个函数
EN

Stack Overflow用户
提问于 2019-11-03 22:03:10
回答 1查看 203关注 0票数 0

下面是我的代码

代码语言:javascript
复制
export const LOG_USER_IN = gql`
  mutation LogUserIn($token: String!) {
    logUserIn(token: $token) @client
  }
`;


export default () => {
  const loginMutation = useMutation(LOG_USER_IN)

  const success = authObj => {
    const { response } = authObj;
    if (response["access_token"]) {
      axios({
        url: "http://localhost:8000/graphql",
        method: "post",
        headers: { Authorization: `Bearer` },
        data: {
          query: print(SOCIAL_AUTH),
          variables: {
            accessToken: response["access_token"],
            provider: "kakao"
          }
        }
      }).then(result => {
        const {
          data: {
            socialAuth: { social, token }
          }
        } = result.data;
        if (social) {
          loginMutation({
            variables: { token }
          });
        } else {
          alert("error");
        }
      });
    } else {
      console.log("error");
    }
  };

它向我显示了类似于"LoginPresenter.js:34 Uncaught (in promise) TypeError: loginMutation is not a function“之类错误

我使用react-apollo-hooks":"^0.5.0",谁来帮帮我?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-03 22:12:55

您错误地使用了useMutation挂钩。

查看文档https://www.apollographql.com/docs/tutorial/mutations/#what-is-the-usemutation-hook

你必须这样做

代码语言:javascript
复制
const [loginMutation, {data}] = useMutation(LOG_USER_IN)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58680905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档