title: Update function value in object array
body: <p>How would I get a randomly generated value in an object array to regenerate each time it is accessed? For example the following code assigns the random value on page load, how would I get it to update each time it's accessed?</p>
  <pre><code>const values = [
    { name: &quot;john&quot;, favouriteColor: getRandomColor() },
    { name: &quot;tom&quot;, favouriteColor: colors[5] },
  ]
  </code></pre>
  <pre><code>{displayColor ? &lt;p&gt;Favourite color is {values[0].favouriteColor}&lt;/p&gt; : &quot;&quot;}
  &lt;button onClick={toggleDisplayColor}&gt;Favourite Color&lt;/button&gt;
  </code></pre>