question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass function callback as props to scenes

See original GitHub issue

Hello, it’s me again. One question, how do we pass function type props to scenes? I am doing something like this:

const stateNavigator = new StateNavigator([
  {key: 'sceneA', trackCrumbTrail: true},
  {key: 'sceneB', trackCrumbTrail: true},
]);
const {sceneA, sceneB} = stateNavigator.states;
sceneA.renderScene = () => <Foo />;
sceneB.renderScene = ({callback}) => <Bar />;

stateNavigator.navigate("sceneB", {
  callback: () => {
    // change something
  }
})

However, the value for callback in sceneB.renderScene is undefined. It seems function type variable is erased from navigationData when encoding data to routeInfo and decoding it back from routeInfo?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
mpiannuccicommented, Apr 28, 2020

So you can pass a function as long as you pass it to render scene. Great thanks for the help!!!

1reaction
grahammendickcommented, Apr 28, 2020

You don’t have to use context. You can pass the function as a prop.

const [val, setVal] = useState(null);
const modalNavigator = useMemo(() => {
  const navigator = new StateNavigator([
    {key: ‘search’}
  ]);
  const {search} = navigator.states;
  search.renderScene = () => <Search setVal={setVal} />
  navigator.navigate('search');
  return navigator;
}, [setVal]);
return (
  <Modal>
    <NavigationHandler stateNavigator={modalNavigator}>
      <NavigationStack />
    </NavigationHandler>
  </Modal>
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

React: Pass a Callback as Props
This is how you allow child components to interact with their parent components. You pass methods to a child just like a regular...
Read more >
Passing Functions to Components
Pass event handlers and other functions as props to child components: ... and it is often the easiest way to pass parameters to...
Read more >
Passing callback functions to child components, is not a ...
I get the error _videos.filteredVideo) is not a function when I try and dispatch an action from a child component. How can I...
Read more >
Callback functions in React
Passing props down to the child is also part of that process, but what gets passed is a bit different. Instead of passing...
Read more >
How to pass a parameter to an event handler or callback
Example 2: In this example, we will use the arrow function to create a new function that calls the function call with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found