反应本机阿波罗客户端 useQuery 无效钩子调用错误
react native apollo client useQuery invalid hook call error
我们如何在 dispatch 函数中使用 appollo/client useQuery?当我尝试时,出现此错误
有些人认为我找到了但我无法修复。
我们如何在 React 或 React Native 中使用 apollo 客户端挂钩事件库?
反应本机 apollo 客户端 useQuery 无效钩子调用错误
Error: Invalid hook call. Hooks can only be called inside of the body of a
function component. This
could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as
React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb .me/react-invalid-hook-call for tips about how to debug and
fix this problem.
- node_modules\react-native\Libraries\LogBox\LogBox.js:148:8 in registerError
.
.
.
actions.js
import { useQuery, gql } from '@apollo/client';
const LOGIN_USER_QUERY = gql`
query{
loginUser(email:$String, password:$String){
userId
token
expiredIn
}
}
`
export const loginUser = (email, password)=>dispatch=> {
const { loading, error, data } = useQuery( LOGIN_USER_QUERY, {
variables:{
email,
password
}
}).then(
data=>{
dispatch({
type: $AT.LOGIN_USER,
payload: data.loginUser
})
}
).catch(err=>{
throw err;
})
if(!data) throw "You couldn't login, Please try again.";
console.log(data);
;
}
成功了谢谢我
const [LoginUserMutation] = useMutation(LOGIN_USER_MUTATION);
const onLoginPressed = () => {
LoginUserMutation({
variables: {
email: username.username,
password: password.password
}).then(data=>{
console.log(data);
}).catch(err=>{
throw err;
})
}
}
我们如何在 dispatch 函数中使用 appollo/client useQuery?当我尝试时,出现此错误 有些人认为我找到了但我无法修复。 我们如何在 React 或 React Native 中使用 apollo 客户端挂钩事件库? 反应本机 apollo 客户端 useQuery 无效钩子调用错误
Error: Invalid hook call. Hooks can only be called inside of the body of a
function component. This
could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as
React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb .me/react-invalid-hook-call for tips about how to debug and
fix this problem.
- node_modules\react-native\Libraries\LogBox\LogBox.js:148:8 in registerError
.
.
.
actions.js
import { useQuery, gql } from '@apollo/client';
const LOGIN_USER_QUERY = gql`
query{
loginUser(email:$String, password:$String){
userId
token
expiredIn
}
}
`
export const loginUser = (email, password)=>dispatch=> {
const { loading, error, data } = useQuery( LOGIN_USER_QUERY, {
variables:{
email,
password
}
}).then(
data=>{
dispatch({
type: $AT.LOGIN_USER,
payload: data.loginUser
})
}
).catch(err=>{
throw err;
})
if(!data) throw "You couldn't login, Please try again.";
console.log(data);
;
}
成功了谢谢我
const [LoginUserMutation] = useMutation(LOGIN_USER_MUTATION);
const onLoginPressed = () => {
LoginUserMutation({
variables: {
email: username.username,
password: password.password
}).then(data=>{
console.log(data);
}).catch(err=>{
throw err;
})
}
}