Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-navigation/core

Package Overview
Dependencies
Maintainers
7
Versions
248
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-navigation/core

Core utilities for building navigators

  • 6.4.17
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
decreased by-2.17%
Maintainers
7
Weekly downloads
 
Created

What is @react-navigation/core?

@react-navigation/core is a core utility for building navigation solutions in React Native applications. It provides the essential building blocks for creating navigators, managing navigation state, and handling navigation actions.

What are @react-navigation/core's main functionalities?

Creating a Navigator

This code demonstrates how to create a custom navigator using @react-navigation/core. It uses the `createNavigatorFactory` and `useNavigationBuilder` functions to set up a basic stack navigator.

const { createNavigatorFactory, StackRouter, useNavigationBuilder } = require('@react-navigation/core');

function MyNavigator({ initialRouteName, children, screenOptions }) {
  const { state, navigation, descriptors } = useNavigationBuilder(StackRouter, {
    initialRouteName,
    children,
    screenOptions,
  });

  return (
    <NavigationContext.Provider value={navigation}>
      <NavigationStateContext.Provider value={state}>
        {state.routes.map((route, i) => (
          <View key={route.key}>
            {descriptors[route.key].render()}
          </View>
        ))}
      </NavigationStateContext.Provider>
    </NavigationContext.Provider>
  );
}

const createMyNavigator = createNavigatorFactory(MyNavigator);

Navigating Between Screens

This code shows how to navigate between screens using the `useNavigation` hook. The `HomeScreen` component includes a button that navigates to the `DetailsScreen` when pressed.

const { NavigationContainer, useNavigation } = require('@react-navigation/core');

function HomeScreen() {
  const navigation = useNavigation();

  return (
    <Button
      title="Go to Details"
      onPress={() => navigation.navigate('Details')}
    />
  );
}

function DetailsScreen() {
  return (
    <Text>Details Screen</Text>
  );
}

const App = () => (
  <NavigationContainer>
    <MyNavigator>
      <Screen name="Home" component={HomeScreen} />
      <Screen name="Details" component={DetailsScreen} />
    </MyNavigator>
  </NavigationContainer>
);

Handling Navigation State

This code demonstrates how to access the current navigation state using the `useNavigationState` hook. The `CurrentRoute` component displays the name of the current route.

const { NavigationContainer, useNavigationState } = require('@react-navigation/core');

function CurrentRoute() {
  const route = useNavigationState(state => state.routes[state.index]);

  return (
    <Text>Current Route: {route.name}</Text>
  );
}

const App = () => (
  <NavigationContainer>
    <MyNavigator>
      <Screen name="Home" component={HomeScreen} />
      <Screen name="Details" component={DetailsScreen} />
    </MyNavigator>
    <CurrentRoute />
  </NavigationContainer>
);

Other packages similar to @react-navigation/core

Keywords

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc