as the title says, I am stuck with some interesting issue with promises. So i have a file that export object with a method, this function gets 2 values and return a setTimeout. the function gets a redux action (function dispatch) and a value for setTimeout. The problem is when I want to make a fetch call and then when the promise fulfilled dispatch the action. the most close I got it this code:
const products = async () => {
const response = await fetch('http://localhost:3009/products');
const data = await response.json();
return data
}
const TIMEOUT = 100
export default {
getProducts: (cb, timeout) => setTimeout(() => {
new Promise(resolve => resolve(products)).then((data)=> cb(data))
}, timeout || TIMEOUT),
}
Thanks to all who try to help