title: Variable is not updated inside a function (using react hooks)
body: <p>I have this code</p>
  
  <pre><code>export const SearchWidget = memo(() =&gt; {
       . . . 
       const requestedProduct = useSelector(state =&gt; state.coverage.requestedProduct);
       . . .
  
      const addSearchWidget = () =&gt; {
  
          search = new Search({
              view: mapView,
              sources: [
                  locatorSearchResource 
              ],
              container: searchContainer.current
          });
  
          search.on('select-result', (data) =&gt; {
              dispatch(actions.registerFoundLocation({
                   id: generateUniqueId(),
                   x: attr.x,
                   y: attr.y,
                   product: requestedProduct // &lt;--- Always old value, 
                   // not updated from redux store!!! How to update it?
              }));
          });
      }
  
      useEffect(() =&gt; {
          addSearchWidget();
      }, []);
  
      return &lt;div ref={searchContainer} /&gt;;
  
  });
  </code></pre>
  
  <p>In dispatch call variable "requestedProduct" has always old value, which it got when it was initialised.</p>
  
  <p>How to get current value of "requestedProduct"?</p>