title: React Native - pass callback to another screen
body: <p>I have a screen with form. Now in that form there's a button that opens another screen where user selects the target option and upon selection they're navigated back to the original form (stack navigator), the reasoning is that user can also create a new option there so they go to the same UI as they would if editing options separately (which they can).</p>
  <p>My code below solution works, <strong>but</strong> I get following warning:</p>
  <blockquote>
  <p>Non-serializable values were found in the navigation state. This can
  break usage such as persisting and restoring state. This might happen
  if you passed non-serializable values such as function, class
  instances etc. in params. If you need to use components with callbacks
  in your options, you can use 'navigation.setOptions' instead. See
  <a href="https://reactnavigation.org/docs/5.x/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state" rel="nofollow noreferrer">https://reactnavigation.org/docs/5.x/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state</a>
  for more details.</p>
  </blockquote>
  <p>Now that link suggests to use <code>setOptions</code> however that is more for like adding a button to header, which is not the case, user selects the option in the target screen by clicking on the option.</p>
  <p>Here are important parts of the code:</p>
  <pre class="lang-typescript prettyprint-override"><code>// MAIN FORM SCREEN
  &lt;Button title={&quot;Some Title&quot;} onPress={openSelectItem}&gt;&lt;/Button&gt;
  
  const openSelectFish = () =&gt; {
      return navigation.navigate(&quot;ItemList&quot;, { sendItemBack: true, onGoBack: onSelectItem });
  };
  
  const onSelectItem = (item: ItemDTO) =&gt; {
      setItem(item.name); // basic useState
  };
  
  // THE OPTIONS SCREEN
  const onChooseItem = (item: ItemDTO) =&gt; {
      console.log(this);
      if ((typeof route !== &quot;object&quot;) || (typeof route.params !== &quot;object&quot;)) return;
      if (!route.params.sendItemBack ?? true) return;
      route.params.onGoBack(item);
      return navigation.goBack();
  };
  // onChooseItem is then used in onPress of each option
  </code></pre>
  <p>Is there a better way how to send callback to the other screen?</p>