我特别尝试使用useRef,但这似乎不起作用,因为我的变量落后了一步。我做错了什么吗?
编辑:第一次尝试时实际上不起作用(单击按钮:selectSession_Click),之后它就可以工作了。为什么在第一次调用时不行呢?
const seqnumRead = useRef(0);
const seqnumWrite = useRef(0);
// Click a session, bring up detail
const selectSession_Click = (event, sessionId) => {
const selectedData = data;
let selSession = selectedData?.filter(s => s.SessionId == sessionId);
SetSessionSelected(selSession[0]);
refetch();
seqnumRead.current = result.payload.read_seqnum;
seqnumWrite.current = result.payload.write_seqnum;
}
// Fetch seq nums of selected session
const queryKey = 'getData';
const { data: result, isFetching, refetch, } = useQuery([queryKey], fetchSeqNums, {
refetchOnWindowFocus: false,
enabled: false,
});
seqnumRead和seqnumWrite落后一步
1条答案
按热度按时间bq3bfh9z1#
我通过result.payload.read在渲染中直接使用www.example.com _seqnum解决了这个问题。