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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-navx

v0.0.8

Published

Navigation and state management in one place for your React Native projects, featuring React Navigation and MobX

Downloads

2

Readme

React NavX

Navigation and state management in one place for your React Native projects.

Featuring React context & hooks, React Navigation, and MobX-React.

Quick Peek

In your main app file:

import React, { useState } from "react"
import { AppRegistry } from "react-native"
import { NavX, types } from "react-navx"
import { AppStoreModel } from "./models/app-store"
import { MainStack } from "./navigation/main-stack"

function App(props) {
  const [appStore] = useState(AppStoreModel.create({}))

  return (
    <NavX
      stores={{ appStore }}
      storeModels={{ appStore: AppStoreModel }}
      screen={MainStack}
    />
  )
}

AppRegistry.registerComponent("MyApp", () => App)

Then, in a screen or other component:

import * as React from "react"
import { useStore, observer } from "react-navx"

function StatusComponent(props) {
  const { status } = useStore("AppStore")

  return <View>{status}</View>
}

export const Status = observer(StatusComponent)

Features

Note that React-NavX supports React Native 0.60 and above only.

Getting Started (React Native)

1. Install react-navx and its dependencies:

yarn add -D react-navx

# or, if you prefer npm
npm i --save-dev react-navx

2. Add a store to your app

Add a MobX-State-Tree (MST) store to your app. See mobx-state-tree documentation for much more on what you can do with MST models.

Note that React-NavX exports everything from mobx-state-tree, so you can access types and other functions from there directly.

import { types } from "react-navx"

// your primary mobx-state-tree store for app state
export const AppStoreModel = types
  .model("AppStore", {
    status: types.optional(types.enumeration(["pending", "loading", "done", "error"]), "pending"),
  })
  .actions(self => ({
    setStatus: newStatus => (self.status = newStatus),
  }))

3. Create a main navigator for your app

This is powered by react-navigation. There are many types of navigators you can use, but here's an example StackNavigator:

import { createStackNavigator } from "react-navx"
import { WelcomeScreen, StatusScreen } from "../screens"

export const MainStack = createStackNavigator(
  {
    welcomeScreen: { screen: WelcomeScreen },
    statusScreen: { screen: StatusScreen },
  },
  {
    headerMode: "none",
  },
)

4. Bring it all together with NavX

Now bring it all together in your main app file. This is often index.js or app.tsx or similar.

import React, { useState } from "react"
import { AppRegistry } from "react-native"
import { NavX, types } from "react-navx"
import { AppStoreModel } from "./models/app-store"
import { MainStack } from "./navigation/main-stack"

function App(props) {
  const [appStore] = useState(AppStoreModel.create({}))

  return (
    <NavX
      stores={{ appStore }}
      storeModels={{ appStore: AppStoreModel }}
      screen={MainStack}
    />
  )
}

AppRegistry.registerComponent("MyApp", () => App)

That's it!

Advanced Usage

Customizing the navigationStore

React-NavX creates its own navigation store by default. If you'd like to create your own and provide it, just use the navigationStore prop on the NavX component.

<NavX
  // ...
  navigationStore={myNavStore}
/>

Adding additional stores

If you want more than just the appStore, just add them to the stores and storeModels props:

<NavX
  stores={{ appStore, loginStore }}
  storeModels={{
    appStore: AppStoreModel,
    loginStore: LoginStoreModel
  }}
  screen={MainStack}
/>

These can then be accessed by any screens or components by using the useStore hook:

import { useStore } from "react-navx"

function MyComponent(props) {
  const loginStore = useStore("loginStore")

  // use loginStore
}

Note: Currently, both stores and storeModels are required to be provided. In the future, I'd like to infer the storeModels to make it easier.

Accessing the RootStore and NavigationStore

The RootStore is exposed via the useRootStore hook:

import { useRootStore } from "react-navx"

function MyComponent(props) {
  const rootStore = useRootStore()

  return <View>{rootStore.appStore.status}</View>
}

The navigationStore is a property on the RootStore:

import { useRootStore } from "react-navx"

function MyScreen(props) {
  const { navigationStore } = useRootStore()

  // do whatever you want with `navigationStore`
}

Help and Support

The best way to get help is to join our vibrant Infinite Red community Slack.

If you have a replicable bug, please feel free to file an issue with steps to reproduce. If you can provide a pull request to fix the issue, even better.

License

This project is released under the MIT license.

Author

React-NavX was created by Jamon Holmgren of Infinite Red.