const STATE_POLL_INTERVAL = 3000;
export const LiveStats: Component = () => {
const query = useQuery(() => ({
queryKey: ["someFetch"],
queryFn: remoteFetch, // just a simple wrapper around fetch()
refetchInterval: STATE_POLL_INTERVAL,
}));
const [statsStore, setStatsStore] = createStore<{ value: TableState | null }>({ value: null });
createEffect(() => {
const data = query.data;
if (data === null || data === undefined) {
return;
}
const newState = evaluateState( // this always returns TableState
extractNames(data),
extractState(data),
extractTimestampToUnix(data),
);
setStatsStore("value", reconcile(newState));
});
const STATE_POLL_INTERVAL = 3000;
export const LiveStats: Component = () => {
const query = useQuery(() => ({
queryKey: ["someFetch"],
queryFn: remoteFetch, // just a simple wrapper around fetch()
refetchInterval: STATE_POLL_INTERVAL,
}));
const [statsStore, setStatsStore] = createStore<{ value: TableState | null }>({ value: null });
createEffect(() => {
const data = query.data;
if (data === null || data === undefined) {
return;
}
const newState = evaluateState( // this always returns TableState
extractNames(data),
extractState(data),
extractTimestampToUnix(data),
);
setStatsStore("value", reconcile(newState));
});