React Data SSR
Server side initial data resolution for react-data-ssr.
Instalation
yarn -i react-data-ssr-server # Or using npm npm -i react-data-ssr-server --save
Examples
The examples folder contains several exmaples.
Usage
Simple Example
// server.js;;;;;;; // React Router Config Routes; const server = ;server ;
Note: The example uses React 16, but it's not a requeriment. React 15 could alse be used. Note 2: The example uses React Router Config, but it's not a requeriment. Any route configuration could be used.
Api
resolveInitialData(branches, extra) -> Promise
Resolves all data, calling the static method getInitialData
of each branch's component.
branches
List with branches. This function support 3 types of branches:
- React Router Config: What is returned by the
matchRoutes
function. Eg:
route: component: Component routes: match: path: '' url: '' params: {} isExact:
- Dictionary: A dictionary with a key
component
that contains the react component. Eg:
component: Component // ...
- Component: Just the React Component.
Note: Remember that the branch will be passed as an argument to the static method getInitialData
. By using the mapArgsToProps
this args can be mapped to the required props for the getData
.
extra
This is an extra, optional argument that will be passed to getInitialData
. It can be used in the mapArgsToProps
to map properties getData
.
Promise
)
Returned value (The function returns a Promise that will be resolved when all the getInitialData
promises resolve.
In the resolution, this promise sends an Object with two keys:
store
: A dictionary that relates successfulgetInitialData
's promises (by the Component's Key) with the resolved data.errors
: A dictionary that relates the rejectedgetInitialData
's promises (by the Component's key) with the failed data.
Note: This promise will never reject