Skip to content

JavaScript Promises – force promise to resolve

Considering that I have the following: The infinite_task is a promise that never resolves or rejects. I tried to use Promise.race but it will never compare both promises, since infinite_task never ends. How can I force infinite_task to resolve after a timeout (in this case, after 5 seconds)? Answer You have a…

Insert object if key doesn’t exist

I’m using recharts to add a new line to a chart where the key value of the object equals to a key value from another object. It works fine when it finds the key but the script doesn’t insert a new object if the key value is not found. I have this array of objects in the state And this