react-nav-current-route-name

1.1.1 • Public • Published

🛣 🚴‍♀️ 🚧 Current Route Name

A memoized selector for redux + react-navigation that will expose the current route name for you!

Installation

yarn add react-nav-current-route-name
npm install --save react-nav-current-route-name

Usage

Two ways:

1 (as an HOC)

  1. import getCurrentRoute
  2. wrap it around your component
  3. You'll have currentRoute available to you with the name of the current route
// if this is the only HOC you have:
import { withCurrentRouteName } from 'react-nav-current-route-name'
export default withCurrentRouteName(MyComponent)
 
// sometimes you'll have a few things using compose:
 
export default compose(
  withCurrentRouteName,
  withApollo,
  withNavigation,
  connectActionSheet
)(MyComponent)
 
// ...
 
componentDidUpdate(nextProps) {
  const { currentRoute } = this.props
  const { currentRoute: nextRoute } = nextProps
}

2 (using mapStateToProps)

  1. import getCurrentRouteName
  2. use it within your current mapStateToProps function
  3. You'll have currentRoute available to you with the name of the current route
import { getCurrentRouteName } from 'react-nav-current-route-name'
 
export default connect(
  mapStateToProps(state => {
    return {
      currentRoute: getCurrentRouteName(state.nav)
    }
  })
)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.1
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.1
    2
  • 1.1.0
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i react-nav-current-route-name

Weekly Downloads

2

Version

1.1.1

License

MIT

Last publish

Collaborators

  • peterpme