'how to put state array equal to another array using use State

I am using useState hook to store an array and initially I am setting it to an empty array. when data is fetched. I am using setState to change it but its not working. thanks in advance

const ShipmentArrival = ({
  isAuthenticated,
  productLoading,
  user,
  products,
  loadProducts,
}) => {
  useEffect(() => {
    loadProducts();
  }, [loadProducts]);

  const [newProducts, setNewProducts] = useState([]);

  if (!productLoading) {
    setNewProducts(products);
    console.log(products);
    for (let i = 0; i < products.length; i++) {
      console.log(newProducts);
      // this log shows that the array is empty
    }
  }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source