title: set hook with variable
body: <p>i have in app component array hook that i need to update, but i have one variable that i cannot update , dont understand why</p>
  <p><em><strong>app component code</strong></em></p>
  <pre><code>function App() {
    const [coins, setCoins] = useState([{name:'Shekel',price:2}, {name:'Dollar',price:3}, {name:'Rubal',price:20}])
    const [changeHistory, setChangeHistory] = useState([])
  
    const updateHistoryChange=(from,to,changeRate,amount)=&gt;{
      setChangeHistory([...changeHistory,{from:from,to:to,changeRate:changeRate,amout:amount,index:changeHistory.length}])
    }
  
  
    return (
      &lt;div className=&quot;App&quot;&gt;
        &lt;Router&gt;
          &lt;Switch&gt;
            &lt;Route exact path=&quot;/&quot; component={() =&gt; { return &lt;HomePage coins={coins} updateHistoryChange={updateHistoryChange} /&gt;}}/&gt;
          &lt;/Switch&gt;
        &lt;/Router&gt;
      &lt;/div&gt;
    );
  }
  
  export default App;
  </code></pre>
  <p><em><strong>Home Page component</strong></em></p>
  <pre><code>export default function HomePage(props) {
      const [inputMoney, setInputMoney] = useState()
      const [from, setFrom] = useState()
      const [to, setTo] = useState()
      const [flag, setFlag] = useState(false)
      const [rateChange,setRateChange]=useState()
  
      const calculate = () =&gt; {
          debugger
          let sum = 0;
          let fromChange;
          let toChange;
          for (let i = 0; i &lt; props.coins.length; i++) {
              if (props.coins[i].name == from) {
                  fromChange = props.coins[i].price;
                  break;
              }
          }
          for (let i = 0; i &lt; props.coins.length; i++) {
              if (props.coins[i].name == to) {
                  toChange = props.coins[i].price;
                  setRateChange(toChange)//not updating it is always undifined
                  break;
              }
          }
          sum = toChange * inputMoney;
          console.log(`${rateChange}`);
          props.updateHistoryChange(from,to,rateChange,inputMoney)
          window.alert(`${sum}`);
  
      }
      const redirect = () =&gt; {
          window.location.href = 'https://www.facebook.com/';
      }
  
      const isHid = () =&gt; {
          if (flag) {
  
          }
      }
  
  
      return (
          &lt;div&gt;
              &lt;h1&gt;Exchange&lt;/h1&gt;
              &lt;p&gt;From:&lt;select id='from' onChange={(element) =&gt;{setFrom(element.target.value)}}&gt;
                  {props.coins.map((element) =&gt; {
                      return (
                          &lt;option value={`${element.name}`} &gt;
                              {element.name}
                          &lt;/option&gt;
                      )
                  })}
              &lt;/select&gt;
                  &lt;input type='number' placeholder='type your money amount' onChange={(element) =&gt; { setInputMoney(Number(element.target.value)) }}&gt;&lt;/input&gt;
              &lt;/p&gt;
  
              &lt;p&gt;
                  To:&lt;select id='to' onChange={(element) =&gt; { setTo(element.target.value) }}&gt;
                      {props.coins.map((element) =&gt; {
                          return (
                              &lt;option value={`${element.name}`}&gt;
                                  {element.name}
                              &lt;/option&gt;
                          )
                      })}
                  &lt;/select&gt;
              &lt;/p&gt;
              &lt;button onClick={calculate} disabled={!inputMoney}&gt;Start&lt;/button&gt;
              &lt;button&gt;Update&lt;/button&gt;
              &lt;button onClick={redirect}&gt;Share on facebook&lt;/button&gt;
              &lt;button&gt;View your exchange list&lt;/button&gt;
              {isHid()}
          &lt;/div&gt;
      )
  }
  
  </code></pre>
  <p>in function calculate when i am setting rateChange like so:</p>
  <pre><code>setRateChange(toChange)
  </code></pre>
  <p>it is not updating my hook
  also tried this not working as well:</p>
  <p>setRateChange(props.coins[i].price)</p>