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

@ethicdevs/react-global-state-router

v0.4.1

Published

A tiny cross-target (web, native) router that complements react-global-state-hooks

Downloads

8

Readme

react-global-state-router

NPM MIT License

Installation

$ yarn add @ethicdevs/react-global-state-router
# or
$ npm i @ethicdevs/react-global-state-router

See this CodeSandBox for a live editable demo. Or just run cd example && yarn && yarn start if you have cloned the repo already.


Usage

Add the GlobalStateRouterProvider just under your GlobalStateProvider so that router/routes/links can use its context.

note: If you do not have a GlobalStateProvider already, please head over to the @ethicdevs/react-global-state-hooks repository and follow the README's instructions first. This library builds upon it.

// src/App.tsx
import React from "react";
import { GlobalStateProvider } from "@ethicdevs/react-global-state-hooks";
+ import { GlobalStateRouterProvider } from "@ethicdevs/react-global-state-router";

import { initialState, rootReducer } from "./state";

const App = () => <>{/* Your app */}</>;

const AppWithProviders = () => (
  <GlobalStateProvider initialState={initialState} rootReducer={rootReducer}>
+    <GlobalStateRouterProvider>
      <App />
+    </GlobalStateRouterProvider>
  </GlobalStateProvider>
);

export default AppWithProviders;

Update your globalState.ts/js or state/index.ts/js file to include the router's exported from this library (so that it can use your store to manage the routing state, giving you full control over routing in your app! 👌) =>

// src/state/index.ts
import { combineModules } from "@ethicdevs/react-global-state-hooks";
+ import { GlobalStateRouterStateModule } from "@ethicdevs/react-global-state-router"

import { AuthModule } from "./auth";
import { HelloModule } from "./hello";

// Auto export everything needed for the Provider
export const { ActionTypes, rootReducer, initialState } = combineModules({
+  ...GlobalStateRouterStateModule,
  auth: AuthModule,
  hello: HelloModule,
});

You are now ready to add your first router and your first routes! Let's see how to simply do that:

// src/App.tsx
import React, { VFC } from "react";

import { GlobalStateProvider } from "@ethicdevs/react-global-state-hooks";
+ import { GlobalStateRouterProvider, Link, Router, Route } from "@ethicdevs/react-global-state-router";

// ... striped for brevity ...

// Add some screens to showcase the features of Link, mainly

+ const OnboardingScreen: VFC = () => {
+   return (
+     <div>
+       <h1>Hey, welcome!</h1>
+       <h2>react-global-state-router is a tiny router for the braves!</h2>
+      <Link screen={"JoinScreen"}>Get started!</Link>
+    </div>
+  );
+};

+const JoinScreen: VFC = () => {
+  return (
+    <div>
+      <h1>Join the move</h1>
+      <h2>Register an account, or login using your existing account.</h2>
+      <Link goBack>Back (pop)</Link>
+      <Link
+        screen={"LoginScreen"}
+        args={{
+          referralUid: "blabbla-uuid",
+        }}
+      >
+        Login
+      </Link>
+      <Link screen={"RegisterScreen"}>Register an account</Link>
+    </div>
+  );
+};

+const RegisterScreen: VFC = () => {
+  return (
+    <div>
+      <h1>Register</h1>
+      <Link screen={"OnboardingScreen"} replace>
+        Back to Onboarding
+      </Link>
+    </div>
+  );
+};

+ const LoginScreen: VFC = () => {
+   return (
+     <div>
+       <h1>Login</h1>
+       <Link screen={"OnboardingScreen"} replace>
+         Back to Onboarding
+       </Link>
+     </div>
+   );
+ };

// Add the router and the routes :)

function App() {
+  return (
+    <Router initialScreen={"OnboardingScreen"}>
+      <Route screen={"OnboardingScreen"} component={<OnboardingScreen />} />
+      <Route screen={"JoinScreen"} component={<JoinScreen />} />
+      <Route screen={"LoginScreen"} component={<LoginScreen />} />
+      <Route screen={"RegisterScreen"} component={<RegisterScreen />} />
+    </Router>
  );
}

License

MIT