title: React - UseState, UseRef..In Trouble
body: <p>Can someone tell me whats wrong ?</p>
  <p>I have a react function component where in I use 'useState' &amp; 'UseRef' on a state variable like so..</p>
  <pre><code>    **A**. `const [nodeslist,_setNodeslist] = useState([]);`
      
      **B**. `const  nodeslistRef = useRef(nodeslist);`
      
      **C**.`const setNodeslist = (data)=&gt;{
                  nodeslistRef.current = data;
                  _setNodeslist(data)
        }`
      
      **D**. somewhere ..on an event which adds nodes...
  
         `
         let n = {id:'someid',attrs:{name:'somename',descr:'somedescr'}};
         setNodeslist(prev=&gt;[...prev,n]);
         `
  
      **E**. in another event handler...click.. I am trtying to find the node clicked..but I cant 
             iterate the 'nodeslist' with ref like so.. 
  
             `nodeslistRef.current.forEach((item,i)=&gt;{
                 .....
             });`
  
             ***GIVES ERROR nodeslistRef.current.forEach is NOT A FUNCTION..***
  
            a. `console.log(nodeslistRef.current)` shows -&gt; prev=&gt;[...prev,n] but not the DATA..
            b. `JSON.stringify(nodeslist)` on page shows expected data..and seems to updating as soon as 
               a node is added to the page..
  </code></pre>
  <p>SO WHATS WRONG ? Can someone help me ? just cant seem to get my head wrapped around it...</p>
  <p><em><strong>As an aside, I am using EXACTLY the same schematics with another state variable and it all works as expected...</strong></em></p>