这是我的代码
const NewVerificationCode = () => {
const { loading, error, data = {}, refetch } = useQuery(CONFIRMATION_CODE, {
skip: true,
notifyOnNetworkStatusChange: true,
fetchPolicy: "no-cache",
});
return <div onClick={() => refetch()}>CONFIRMATION</div>;
};
const CONFIRMATION_CODE = gql`
query {
my {
sendNewTokenForConfirmation
}
}
`;
我提出请求时遇到错误
未捕获的TypeError:无法读取未定义的属性“ refetch”
答案 0 :(得分:1)
https://pastebin.com/gEF5s5Yc #include "classes.h" void Library::check_Out(Patron& person, Book& a){ if (check_Book(a) && check_User(person)) { if (!person.check_If_Owes_Fee()) { a.checkOut(); Transaction person.get_Patron_Name(); //error here } else cout << "Can't perform operation. User owes a fee"; } else cout << "Invalid, user or book not in library"; }
似乎您试图从未定义的#include "classes.h"
int main() {
Book one("123H", "Hey", "Cool", Date(31, 12, 2020), Genre::FICTION);
Book two("123H", "Hey", "Cool", Date(31, 12, 2020), Genre::CHILDREN);
operator<<(cout, one);
return 0;
}
错误“逃脱”-不建议使用的方法...使用
data = {}
...在主要内容之前或
data
if(loading) return <Loading />
选项阻止执行钩子,因此不可能if(data) return <div onClick={() => refetch()}>CONFIRMATION</div>;
return null;
。
只需使用skip
或使用某种状态来控制refetch
选项,例如:
useLazyQuery