Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React native, multiple records getting pushed after 2nd object being pushed onto the array

$
0
0

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);    };

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>