@finfe/react-kits-server

Express server for react-kits

Stats

StarsIssuesVersionUpdatedCreatedSize
@finfe/react-kits-server
4.0.03 years ago4 years agoMinified + gzip package size for @finfe/react-kits-server in KB

Readme

react-kits-server

Express server for server-side rendering with data prefetching.

Install

yarn add @finfe/react-kits-server

API

import { createReactServer } from 'react-kits-server';

import createStore from '../store/createStore';
import { getInitialData } from '../routes';
import { HOME_PATH, ASSET_URL } from '../url';
import CoreLayout from '../layouts/CoreLayout';

const app = createReactServer({
  createStore,
  getInitialData,
  homePath: HOME_PATH,
  assetUrl: ASSET_URL,
  customMiddleware: expressIns => {},
  onRender: () => <CoreLayout />
});

createStore()

function that must return Redux store.

getInitialData(req, store)

function that must return Promise.

customMiddleware(expressIns)

functions that receive express instance and runs before SSR requests

onRender({ expressCtx, store })

function that must return either

  • React element
  • Promise of React element

mapAppString(appStr)

function that accepts renderToString result and return new string

createApolloClient(expressCtx)

function that must return Apollo client to be used on SSR server

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.