To anybody from the future, Here is what I came up with, I used refetch
which is returned by RTK-query hooks.
// stocks component
import { useGetStocksQuery } from '../features/stocksList/stocksListApiSlice';
import { useEffect, useRef } from "react";
const Stocks = () => {
const tickerArray = [
"AAPL",
"TSLA",
"NKE",
"MSFT",
"AMZN",
"GOOGL",
"META",
"SNAP",
"NFLX"
];
const stockTimerId = useRef();
let {
data: list,
refetch
} = useGetStocksQuery({tickerArray});
useEffect(() => {
stockTimerId.current = await setInterval(() => refetch(), 10000);
}
return () => clearInterval(stockTimerId.current)
})
return (
<>Your JSX goes here</>
)
}
export default Stocks