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

rn-razor

v0.4.2

Published

Router for React Native with declarative configuration similar to React Router.

Downloads

21

Readme

(React Native) Razor

Router for React Native with declarative configuration similar to React Router.

  • Declarative configuration (using <Route> similar to react-router)
  • Idiomatic React; no imperative API or self-contained state (unlike react-router)
  • Uses NavigatorExperimental (soon to replace Navigator and NavigatorIOS in core React Native)

Install

npm install rn-razor --save

Usage

Configuration
import {Router, Route, StateUtils} from "rn-razor";

class Application extends React.Component {
  state = {
    routerState: StateUtils.create({initialRoute: "index"}),
  };

  render() {
    <Router routerState={this.state.routerState}>
      <Route name="index" component={Index} />
      <Route name="profile" component={Profile} />
      <Route name="contacts" component={ContactList} />
      <Route name="contact" component={ContactDetail} />
    </Router>
  }
}
Navigation
import {StateUtils} from "rn-razor";

routerState = StateUtils.push(routerState, "profile");
routerState = StateUtils.pop(routerState);
routerState = StateUtils.jumpTo(routerState, "contact", {id: 10});
routerState = StateUtils.resetTo(routerState, "contact", {id: 10});

Reference

<Router>

routerState

The current state of navigation.

Can be initialized to an initial route with StateUtils.create({initialRoute: "..."}).

Example
{
  index: 1,
  routes: [
    { name: "index" },
    { name: "contact-detail", params: { id: 3 } },    
  ]
}
children

A collection of <Route> components providing the declarative configuration.

onWillFocus

Called when a route is about to be rendered or "focused" (name comes from react-native). This is called after the route's onEnter (if present).

onDidFocus

Called when a route has been rendered or "focused". This is called after the route component's componentDidMount (tip: good place to hide a splash screen from rn-splash-screen).

createElement

When the router is ready to render a specific scene, it will use this function to create the elements.

Default
function createElement(Component, props) {
  return <Component {...props} />
}
render

When the router is ready to render the scene stack, it will use this function.

Use this callback to add persistent views around the scene stack. Perhaps a navigation drawer or wrap scenes in KeyboardAvoidingView from react-native.

Default
function render(scenes) {
  return scenes;
}

<Route>

name

The route key to use as a unique index during navigation.

component

The component to be rendered for the route.

onEnter

Called when a route is about to be entered.

onLeave

Called when a route is about to be exited. Called before the next route's onEnter.

children

A collection of <Route> components that are treated as a group, invoking their parent's onEnter and onLeave as a group.

For instance, a group of routes can be given a single onLeave or onEnter that is called when the router is no longer in the group or when entering the group for the first time.

Note that a <Route> cannot have both a component and children as component nesting is not currently supported.