Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-whereto

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-whereto

Where to?

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Whereto

Where to?

Install

yarn add react-whereto

Use

Make a dispatcher

// my-dispatcher.js
import { RouteDispatcher } from 'react-whereto'

async function myPromise(who) {
  return Promise.resolve(1);
}

export const routeDispatcher = new RouteDispatcher()
  .route('/', { strict: true, exact: true }, () => dispatch => dispatch({ type: 'MY_ACTION' }))
  .route('/hello/:who', ({ params: { who } }) =>  myPromise(who))
  .route('/world', { type: 'MY_OTHER_ACTION' });

Wrap it with whatever you like (probably a redux dispatcher)

// my-loader.js
import { dispatchLoader } from 'react-whereto'
import { createStore, applyMiddelware } from 'redux';
import thunk from 'redux-thunk';
import routeDispatcher from './my-dispatcher';

const reducer = state => state; //.. a reducer, you know

const store = createStore(reducer, {}, applyMiddelware(thunk))

const locationHandler = dispatchLoader(routeDispatcher)(store.dispatch);

locationHandler('/hello/bob').then(() => {
  console.log('myPromise ran!');
});

Or let it load automatically with every route change.

// my-app.js
import React from 'react';
import { Provider } from 'react-redux';
import { DispatcherProvider } from 'react-whereto';
import { BrowserRouter, withRouter } from 'react-router-dom';
import routeDispatcher from './my-dispatcher';

const reducer = state => state; //.. a reducer, you know

const store = createStore(reducer, {}, applyMiddelware(thunk))

class NavOnLoadBase extends React.Component {
  componentDidMount() {
    // now the promise will load again!
    this.props.history.push('/hello/bob');
  }
  render() {
    return <div>Hi App</div>;
  }
}

const NavOnLoad = withRouter(NavOnLoadBase);

const App = () => (
  <BrowserRouter>
    <Provider store={store}>
      <DispatcherProvider store={store} dispatcher={routeDispatcher}>
        <NavOnLoad />
      </DispatcherProvider>
    </Provider>
  </Router>
);

export App;

Example

yarn install
yarn run example

Then open your browser to http://127.0.0.1:3000

License

react-whereto is free software under the MIT license.

Keywords

FAQs

Package last updated on 07 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc