İlker
İlker

Reputation: 2090

React Native - How to get initial navigation state in React Navigation

I'm trying to get initial state in the same format as onStateChange prop provides in NavigationContainer. onStateChange doesn't fire on initial render. In the example below, I managed to get state when navigating between screens, but not on the first one. Any ideas?

export default function App() {
  const [pageState, setPageState] = React.useState();

  return (
    <NavigationContainer onStateChange={(state) => setPageState(state)}>
      <RootNavigation />
    </NavigationContainer>
  );
}

Upvotes: 1

Views: 1052

Answers (1)

Pedro Feltrin
Pedro Feltrin

Reputation: 458

Try using the onReady method from the NavigationContainer From the docs: https://reactnavigation.org/docs/navigation-container#onready

Upvotes: 2

Related Questions