title: how to update specific index of integer array in functional component setState in react js
body: <p>first i make price int array and store int numbers in hook only once then i want to update specific index of that price array in update value but didnt able to update setPrice specific index instead it return  me to array with only one value but i want all values with updated index value like [0,3,4,5,6] update id 1 then in my logic multiply by 2 it should do [0,6,4,5,6] but it return me only [6]</p>
  <pre><code>import React, {useEffect,useState,useContext } from 'react';
  import {Cartlist} from '../Global/CartContext.js';
  const Cart=()=&gt;{
    const {ShoppingCart,totalprice,quantity,dispatch} = useContext(Cartlist);
    const [price,setPrice]=useState([])
    const Style={
      width:'100px',
      height: '100px',
    }
    useEffect(()=&gt;{
      ShoppingCart.map((products)=&gt;{
        setPrice(prev=&gt;[...prev,products.price]);
      })
    },[])
    const updatevalue=(e)=&gt;{
      ShoppingCart.map((products)=&gt;{
        if (e.target.id===products.id){
            setPrice(price=&gt;price[products.id-1]*2);
        }
    })
    }
    return (
      &lt;div className='container'&gt;
        {ShoppingCart.length &gt; 0 ?
          ShoppingCart.map((products)=&gt;(
            &lt;div&gt;
              &lt;span&gt;&lt;img style={Style} src={products.image}&gt;&lt;/img&gt;&lt;/span&gt;
              &lt;span&gt;{price}&lt;/span&gt;
              &lt;span&gt;{quantity}&lt;/span&gt;
              &lt;span&gt;&lt;button id={products.id} onClick={updatevalue}&gt;+&lt;/button&gt;&lt;/span&gt;
            &lt;/div&gt;
          ))
        :''}
      &lt;/div&gt;
    )
  }
  export default Cart
  </code></pre>