This document uses rtype for type signatures.
Wraps your rootEpic in a function that allows renderToString
to inspect the observables within the epicMiddleware.
import interface { Epic } from 'redux-observable';
interface WrappedEpic { ...Epic };
import { createEpicMiddleware } from 'redux-observable';
import { wrapRootEpic } from 'react-redux-epic';
import { fetchDataCompleteActionCreator } from './action-creators.js';
const rootEpic = actions => actions.ofType('FETCH').switchMap(() => Observable
.ajax('/api/data')
.map(fetchDataCompleteActionCreator);
);
const wrappedEpic = wrapRootEpic(rootEpic);
const epicMiddleware = createEpicMiddleware(wrappedEpic);
renderToString takes your wrappedEpic and your react app and will trigger a render, wait for all of your epics to complete, then trigger a final render.
renderToString(
element: ReactElement,
wrappedEpic: WrappedEpic
) => Observable[{ markup: String }];
import { renderToString } from 'react-redux-epic';
renderToString(<App />, wrappedEpic)
.subscribe(({ markup }) => {
// if using Express
res.render('index', { markup });
});
Optional: Wraps react-dom
's render method in an observable. Calls next
when the render is complete.
render(
element: ReactElement,
container: DOMElement
) => Observable;
import { render } from 'react-redux-epic/client';
render(<App />, document.getElementById('app-div'))
.subscribe(() => console.log('rendered!'));