React Native, Im trying to check the whether the object is present in the array or not, if present Im replacing the object with the new one, but after the 2nd object is inserted 3rd object is pushed twice, 4th object 4 times, Im not understanding why this behaviour is happening, is it because of immutable array or what?
useEffect(() => { if (route.params && route.params.lookup_scan) { showShipments(); } }, [route]); const showShipments = () => { if (SegregationContext.shipments.length > 0) { SegregationContext.shipments.forEach((item, key: number) => { if (item.lookup_scan === route.params.lookup_scan) { SegregationContext.shipments[key] = route.params; } else { SegregationContext.shipments.push({ ...route.params }); } }); } else { SegregationContext.shipments.push(route.params); } setShipments([...SegregationContext.shipments]); setIsLoader(false); };