下面是我的代码
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",谁来帮帮我?
发布于 2019-11-03 22:12:55
您错误地使用了useMutation挂钩。
查看文档https://www.apollographql.com/docs/tutorial/mutations/#what-is-the-usemutation-hook
你必须这样做
const [loginMutation, {data}] = useMutation(LOG_USER_IN)https://stackoverflow.com/questions/58680905
复制相似问题