React fetch data in server before render.
- Simple
- Support Async/Await syntax
- Support Redux
- Recursive (fetchData for all children)
Usage:
//server.js; //Important require; { }
Add "fetchData" to React.Component-Lifecycle on server-side
//AppView.js - React.Component; Component { return thisprops; }; { this; } { return <div> AppView thispropsappdata ? <div> JSON </div> : null </div> ; }
Prepare store (add FetchData-Middleware)
//prepareStore.js;;;; { return ;}
Write action-creator for fetchData:
//actionCreators.js; => { return { ifstatus return; ; return { ; }; }}
On Server:
- First call "appFetchData" should be return unique promise
- Other calls "appFetchData" should be return undefined
On Client:
- Any call "appFetchData" should be return new promise
More details: https://github.com/MrCheater/react-fetch-data/example/src
For Developers
npm install -g mochanpm install -g babel-clinpm install -g webpacknpm run testnpm build:examplenpm run exampleexample/dist/index.html