title: Can we use useMemo when memoized object is used in useEffect?
body: <p>Imagine this case.</p>
  <p>A hook that receives an object and based on the object's properties does some computing and returns the result.</p>
  <pre><code>export const useTestHook = (someOject) =&gt; {
    const [updated, set] = useState({ val1: null, val2: null });
  
    useEffect(() =&gt; {
      set({
        val1: `${someOject.val1}_-`,
        val2: `${someOject.val2}_-`,
      })
    }, [someOject]);
  
    return updated;
  }
  </code></pre>
  <p>The component using the hook has these values separated so a new object needs to be initialized so it can be passed to the hook. The result of the hook is then passed via some callback back to the parent.</p>
  <pre><code>function TestComp({ onChange, parentValue }) {
    const [value1, setValue1] = useState('value1');
    const [value2, setValue2] = useState('value2');
  
    // since mergedValues is used as dependency of the hook I need to 'memoize' it otherwise it gets 
    // recreated on each re-render and will cycle 
    const mergedValues = useMemo(() =&gt; ({
      val1: value1,
      val2: value2
    }), [value1, value2]);
  
    const updatedVals = useTestHook(mergedValues);
  
    useEffect(() =&gt; {
      onChange(updatedVals);
    }, [onChange, updatedVals]);
  
    return (
      &lt;div&gt;
        Hello
      &lt;/div&gt;
    );
  }
  </code></pre>
  <p>The parent can do some other computing on that value and the result returns back to the child.</p>
  <pre><code>function App() {
    const [value, set] = useState('value1');
  
    return (
      &lt;TestComp onChange={set} parentValue={value} /&gt;
    );
  }
  </code></pre>
  <p>What is the correct way to handle object creation in a react component when the object is used as a dependency of some effect? Can be the <code>useMemo</code> hook used for it?</p>
  <pre><code>const mergedValues = useMemo(() =&gt; ({
      val1: value1,
      val2: value2
    }), [value1, value2]);
  </code></pre>
  <p>Official docs say <strong>&quot;You may rely on useMemo as a performance optimization, not as a semantic guarantee.&quot;</strong>
  <a href="https://reactjs.org/docs/hooks-reference.html#usememo" rel="nofollow noreferrer">https://reactjs.org/docs/hooks-reference.html#usememo</a></p>
  <p>Another way would be changing the hook's prop from an object to simple values and creating the object from these values inside hook's useEffect but this approach is no go for me.</p>