Skip to content

Adapts react-router hooks to promises instead of callbacks.

License

Notifications You must be signed in to change notification settings

nsaunders/react-router-promises

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)} />

About

Adapts react-router hooks to promises instead of callbacks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published