npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@truefit/bach-react-navigation

v2.1.0

Published

connect your composed components to react-navigation

Downloads

38

Readme

@truefit/bach-react-navigation

Overview

This set of enhancers exposes the hooks from react navigation to the bach compose chain.

Installation

npm install @truefit/bach-react-navigation @truefit/bach

or

yarn add @truefit/bach-react-navigation @truefit/bach

Enhancers

withFocusEffect

Sometimes we want to run side-effects when a screen is focused. A side effect may involve things like adding an event listener, fetching data, updating document title, etc. While this can be achieved using focus and blur events, it's not very ergonomic.

Example

Typescript

import React from 'react';
import {compose} from '@truefit/bach';
import {withFocusEffect} from '@truefit/bach-react-navigation';
import {View, Text} from 'react-native';

const Component = () => (
  <View>
    <Text>
      Hello World
    </Text>
  </View>
);

export default compose(
  withFocusEffect(() => {
    console.log('Hello World');
  }),
)(Component);

Javascript

import React from 'react';
import {compose} from '@truefit/bach';
import {withFocusEffect} from '@truefit/bach-react-navigation';
import {View, Text} from 'react-native';

const Component = () => (
  <View>
    <Text>
      Hello World
    </Text>
  </View>
);

export default compose(
  withFocusEffect(() => {
    console.log('Hello World');
  }),
)(Component);

React Navigation Hook useFocusEffect

withIsFocused

We might want to render different content based on the current focus state of the screen.

Example

Typescript

import React from 'react';
import {compose} from '@truefit/bach';
import {withIsFocused, IsFocused} from '@truefit/bach-react-navigation';
import {View, Text} from 'react-native';

type Props = {
} & IsFocused;

const Component = ({isFocused}: Props) => (
  <View>
    <Text>
      {isFocused ? 'Hi' : 'Shhh'}
    </Text>
  </View>
);

export default compose(
  withIsFocused()
)(Component);

Javascript

import React from 'react';
import {compose} from '@truefit/bach';
import {withIsFocused} from '@truefit/bach-react-navigation';
import {View, Text} from 'react-native';

const Component = ({isFocused}) => (
  <View>
    <Text>
      {isFocused ? 'Hi' : 'Shhh'}
    </Text>
  </View>
);

export default compose(
  withIsFocused()
)(Component);

React Navigation Hook useIsFocused

withLinking

Lets us handle deep links in our apps.

React Navigation Hook useLinking

withNavigation

Gives access to navigation object. It's useful when you cannot pass the navigation prop into the component directly, or don't want to pass it in case of a deeply nested child.

Example

Typescript

import React from 'react';
import {compose} from '@truefit/bach';
import {withNavigation} from '@truefit/bach-react-navigation';
import {NavigationProp} from '<your navigation prop>';

import {View, Button} from 'react-native';

type Props = {
  navigation: NavigationProp;
  handeClick: () => void;
}

const Component = ({handlePress}: Props) => (
  <View>
    <Button title="Click Me" onPress={handlePress} />
  </View>
);

export default compose<Props>(
  withNavigation(),

  withCallback<Props>('handlePress', ({navigation}) => () => {
    navigation.goBack();
  }),
)(Component);

Javascript

import React from 'react';
import {compose} from '@truefit/bach';
import {withNavigation} from '@truefit/bach-react-navigation';

import {View, Button} from 'react-native';

const Component = ({handlePress}) => (
  <View>
    <Button title="Click Me" onPress={handlePress} />
  </View>
);

export default compose<Props>(
  withNavigation(),

  withCallback<Props>('handlePress', ({navigation}) => () => {
    navigation.goBack();
  }),
)(Component);

React Navigation Hook useNavigation

withNavigationState

Gives access to the navigation state of the navigator which contains the screen.

Example

Typescript

import React from 'react';
import {compose} from '@truefit/bach';
import {withNavigationState} from '@truefit/bach-react-navigation';

import {View, Text} from 'react-native';

type Props = {
  routeNames: string;
}

const Component = ({routeNames}: Props) => (
  <View>
    <Text>{routeNames}</Text>
  </View>
);

export default compose<Props>(
  withNavigationState('routeNames', state => state.routeNames.join(',')),
)(Component);

Javascript

import React from 'react';
import {compose} from '@truefit/bach';
import {withNavigationState} from '@truefit/bach-react-navigation';

import {View, Text} from 'react-native';

const Component = ({routeNames}) => (
  <View>
    <Text>{routeNames}</Text>
  </View>
);

export default compose(
  withNavigationState('routeNames', state => state.routeNames.join(',')),
)(Component);

React Navigation Hook useNavigationState

withRoute

Gives access to route object. It's useful when you cannot pass the route prop into the component directly, or don't want to pass it in case of a deeply nested child.

Example

Typescript

import React from 'react';
import {compose} from '@truefit/bach';
import {withRoute} from '@truefit/bach-react-navigation';

import {RouteProp} from '@react-navigation/native';
import {NavigationProp} from '<your navigation prop>';

import {View, Text} from 'react-native';

type Props = {
  route: RouteProp<NavigationProp, 'RouteKey'>;
}

const Component = ({route}: Props) => (
  <View>
    <Text>{route.key}</Text>
  </View>
);

export default compose<Props>(
  withRoute(),
)(Component);

Javascript

import React from 'react';
import {compose} from '@truefit/bach';
import {withRoute} from '@truefit/bach-react-navigation';

import {View, Text} from 'react-native';

const Component = ({route}) => (
  <View>
    <Text>{route.key}</Text>
  </View>
);

export default compose<Props>(
  withRoute(),
)(Component);

React Navigation Hook useRoute

withScrollToTop

The expected native behavior of scrollable components is to respond to events from navigation that will scroll to top when tapping on the active tab as you would expect from native tab bars.

React Navigation Hook useScrollToTop