🗂 react-get-app-data
Simple React HOC for getting intial and subsequent async data + SSR
Install
$ yarn add react-get-app-data
API
Example
As HOC
const Page = <div>Hello username!</div> const PageWithData = Page ReactDOM
Or as static property inside component
Component static defaultProps = user: {} static async { const user = await return user } { const user = thisprops return <div>Hello username!</div> } const PageWithData = Page ReactDOM
Server-Side Rendering
With two-step rendering on server
// server.js { const appElement = <App /> }
Hydrate app and initialData in client
// client.js // Get server stateconst initialData = window_ssr || {} // Restore app state // Render appReactDOM
Related
- react-tree-walker - inside
getAppInitialData
- webpack-hot-server-middleware - server-side entry for webpack
- goremykina.com - usage example
MIT © John Grishin