Hi All,
I have just started up with Redux in my app for SSR and have got it work just fine. I have a questions on initial data provided to page load may be hampering my app load performance, it would be really helpful if you could help me with loading only limited data on landing.
Below is my code
Server
onPageLoad((sink) => {
const context = {};
const initial = quizGetAll.call({}); //this query loads all the data and send it to client via redux
const store = createStore(mainReducer, { quiz: initial }, applyMiddleware(thunk));
const App = props => (
<Provider store={store}>
<StaticRouter location={props.location} context={context}>
{Routes}
</StaticRouter>
</Provider>
);
App.propTypes = {
location: object.isRequired,
};
const preloadedState = store.getState();
sink.renderIntoElementById('app', renderToString(<App location={sink.request.url} />));
const helmet = Helmet.renderStatic();
sink.appendToHead(helmet.meta.toString());
sink.appendToHead(helmet.title.toString());
sink.appendToBody(`
<script>
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(/</g, '\\u003c')}
</script>
`);
});
Client
const preloadedState = window.__PRELOADED_STATE__; //This is loading all the data of my app into client
delete window.__PRELOADED_STATE__;
const store = createStore(mainReducer, preloadedState, applyMiddleware(thunk));
const App = () => (
<Provider store={store}>
<BrowserRouter>
<Switch>
{Routes}
</Switch>
</BrowserRouter>
</Provider>
);
//Render Routes to client with a delay of 2s to allow server to render first
onPageLoad(() => {
ReactDOM.hydrate(<App />, document.getElementById('app'));
});
Please guide me in loading only 20 records per page(planning to do pagination) that way i think the page performance will improve.
TIA