iniquest
A lightweight (~30 LOC) library to help with async data fetching before rendering with react-router.
Installation
$ npm i iniquest -S
Usage
Below is an example of how you could use iniquest with express. For a more detailed example, that also demonstrates acting on POST
-requests, check out maximilianschmitt/full-stack-react.
server.js
const routes = <Route handler=App> <Route name="home" path="/" handler=Home /> <Route name="ip" path="/ip" handler=Ip /> </Route>; app;
app-component.js
Here, RouteHandler
will be the Ip
component below if the user navigates to /ip
.
Component { return <div className="app"> <RouteHandler initialState=this /> </div> ; } mixin;
ip-component.js
Component { return <div>Your ip is: thisstateip</div>; } mixin; // implement prepareForRequest on a RouteHandler// to make an async request before renderingIp { return ;};
Todo
-
Add ability for parent
RouteHandler
s to pass params to theprepareForRequest
of a childRouteHandler
, maybe like this:Component : optsComponent : initialState -
Find a simple solution so that (1) can optionally run
prepareForRequest
-calls in parallel ifopts
for the child's preparation are not dependent on the parent'sprepareForRequest