title: Randomly map data using useRef - ReactJS
body: <p>I want to display the data randomly for a particular id, and every time the same user loads the page gets the same data displayed first time. I am unable to randomly set data</p>
  <pre><code>const Data = () =&gt; {
   
    
    const { datas } = useSelector((state) =&gt; state.data);
    const dispatch = useDispatch();
    const history = useHistory();      
    useEffect(() =&gt; {
      if (!datas) {
        dispatch(fetchDatas(history));
      }
    }); 
      const adv = React.useRef(data[Math.floor(Math.random() * data.length)]).current;
      // console.log(data + &quot;datacoming&quot;);
      console.log(adv + &quot;adv&quot; );
              
   return (
       !datas?.length ? &lt;CircularProgress /&gt; : (
        &lt;&gt;
        &lt;List component=&quot;nav&quot;&gt;
          {datas.map(data =&gt; (&lt;ListItem key={data.id} button&gt;
  
            &lt;h2&gt;{data.code}&lt;/h2&gt;
            &lt;p&gt;&lt;/p&gt;
            &lt;p&gt;{data.name} &amp;nbsp;&lt;/p&gt;
  
            &lt;p&gt;{data.intro} &amp;nbsp;&lt;/p&gt;   
          &lt;/ListItem&gt;
  
          ) 
          )}
         &lt;/List&gt;&lt;/&gt;
      )
    );
  };
  
  export default Data;
  </code></pre>
  <p>Here I want to display the list data randomly, need help. Unable to get the list data randomly. What wrong i am doing in this?</p>