ptr-core
ssr
Api
createRenderFn({
maxRetries,
createDataFn,
createElFn,
requestCounter,
});
createRequestCounter(options);
createAsyncMiddleware(requestCounter);
Demo
import {createStore} from 'redux';
import {
createRenderFn,
createRequestCounter,
createAsyncMiddleware,
} from '@gisatcz/ptr-core';
function createStore() {
const requestCounter = createRequestCounter();
const store = createStore(reducer, {}, createAsyncMiddleware(requestCounter));
return {
store,
requestCounter,
};
}
function handler(req, res) {
const {store, requestCounter} = createStore();
const createEl = () => {
const appEl = (
<UIDReset>
<Provider store={store}>
<App />
</Provider>
</UIDReset>
);
if (shouldRedirect) {
res.redirect(301, requiredUrl);
return;
}
return appEl;
};
const renderFn = createRenderFn({requestCounter, createEl});
return requestCounter.createReadyP().then(() => renderFn());
}