react-router-promises

1.0.4 • Public • Published

react-router-promises

Adapts react-router hooks to promises instead of callbacks.

Instead of this:

function loadUsersIntoStore(nextState) {
  return new Promise((resolve, reject) => {
    // fetch user listing and add it to the data store
  });
}

function loadUsersOnEnter(nextState, replace, callback) {
  loadUsersIntoStore(nextState).then(callback);
}

function loadUsersOnChange(prevState, nextState, replace, callback) {
  loadUsersIntoStore(nextState).then(callback);
}

// ...

<Route path="/users" component={UserListing} onEnter={loadUsersOnEnter} onChange={loadUsersOnChange} />

This library will allow you to do this:

import { enter, change } from 'react-router-promises';

function loadUsersIntoStore(nextState) {
  return new Promise((resolve, reject) => {
    // fetch user listing and add it to the data store
  });
}

// ...

<Route path="/users" component={UserListing} onEnter={enter(loadUsersIntoStore)} onChange={change(loadUsersIntoStore)} />

Package Sidebar

Install

npm i react-router-promises

Weekly Downloads

2

Version

1.0.4

License

MIT

Last publish

Collaborators

  • therealnicksaunders