I have two state variables
const [cartList, setCartList] = useState([]);
const [tabledata, setTabledata] = useState(localStorage.getItem("items"))
tableData is initiated from local storage
cartList will be an array of objects with complete list and an example will be like
[
{id: 1, name: pen, sku: 1001, price: 5},
{id: 2, name: a4-book, sku: 1005, price: 2},
{id: 3, name: usb-16gb, sku: 1010, price: 15},
{id: 4, name: usb-32gb, sku: 1021, price: 28}
]
tableData is also an object array and will have some items and an example will be like
[
{id: 2, name: a4-book, sku: 1005, price: 1.5},
{id: 4, name: usb-32gb, sku: 1021, price: 22}
]
cartList has my latest price for each item, i want to update the tabledata to get the price for corresponding items (by id) from cartList every 5 minutes.
what is the best way to achieve this continuously ? so the tabledata element price is up to date with cartList price for corresponding items?