2.0.1 • Published 5 years ago

react-navigation-mobx-helpers v2.0.1

Weekly downloads
13
License
MIT
Repository
github
Last release
5 years ago

react-navigation-mobx-helpers

React-Navigation bindings for MobX

Installation

npm install react-navigation-mobx-helpers --save

Usage

import React from 'react';
import { Provider, inject, observer } from 'mobx-react';
import { StackNavigator } from 'react-navigation';
import NavigationStore from 'react-navigation-mobx-helpers';

const RootNavigator = StackNavigator(RouteConfigs);

const rootNavigation = new NavigationStore();

class Root extends React.Component {
  render() {
    return (
      <Provider rootNavigation={rootNavigation}>
        <App />
      </Provider>
    );
  }
}

@inject('rootNavigation')
@observer
class App extends React.Component {
  render() {
    const { rootNavigation } = this.props;
    return <RootNavigator ref={rootNavigation.createRef} />;
  }
}

API

ActionParameterDescription
createRefref: React.ComponentSave an instance of navigation to store
dispatchaction: NavigationActionSend an action to router
getParamparamName: string, fallback?: NavigationParamsGet a specific param with fallback
setParamsnewParams: NavigationParamsMake changes to route's params
navigate{ routeName: string, params?: NavigationParams, action?: NavigationAction, key?: string } OR routeName: string, params?: NavigationParams, action?: NavigationActionGo to another screen, figures out the action it needs to take to do it
pushrouteName: string, params?: NavigationParams, action?: NavigationActionNavigate forward to new route in stack
replacerouteName: string, params?: NavigationParams, action?: NavigationActionReplace the current route with a new one
goBackrouteKey?: string \| nullClose active screen and move back in the stack
popn?: number, params?: { immediate?: boolean }Go back in the stack
popToTopparams?: { immediate?: boolean }Go to the top of the stack