我尝试在组件呈现后运行测试查询。贝娄我的密码。
useEffect中执行的testQuery函数不会执行任何操作。我不知道为什么。。。知道吗?
const Card2 = (props) => {
const [count, setCount] = useState(0);
console.log (`count :: ${count}`);
const [testQuery,{ loading, data}] = useLazyQuery (TEST_QUERY);
if(loading) debugger;
useEffect(() => {
console.log('useEffect');
testQuery();
debugger;
},[count]);
return(
<div className={classes.Content} >
<button className={classes.Price} onClick = {() => setCount(count + 1)}>
</button>
</div>
);
};
const Card2 = (props) => {
const [count, setCount] = useState(0);
const [fetchedData, setFetechedData] = useState([])
console.log (`count :: ${count}`);
const [testQuery,{ loading, data}] = useLazyQuery (TEST_QUERY);
if(loading) debugger;
useEffect(() => {
console.log('useEffect');
testQuery();
debugger;
},[count]);
useEffect(() => {
data && setFetechedData([...fetchedData, data])
},[data]);
return(
<div className={classes.Content} >
<button className={classes.Price} onClick = {() => setCount(count + 1)}>
</button>
</div>
);
};
您必须以某种方式处理来自查询的响应。您可以添加另一个useEffect来侦听更改。