Example how to use in SPA
darkowic opened this issue · 5 comments
Hello!
I'm new to SSR. Is it possible to use this as a part of single page application (SPA)? Together with react router on both sides client and server. I can not imagine it now.
Thanks. Great job!
@darkowic Just look at his repos, there's another one with an example. Ultimately, I think he might be using some of our universal components to route and rendering. Pretty much, this is only on the server side.
Put that in your express server, once.
https://github.com/rookLab/react-component-caching-demo
const ReactCC = require("react-component-caching");
const cache = new ReactCC.ComponentCache();
app.get('/example', async (req,res) => {
const renderString = await ReactCC.renderToString(<App />, cache);
res.send(renderString);
});
The case it that I do not want to cache the whole App but only some components. I use react router and this has to be there. But I'm thinking that the solution might be to export routes to some configuration object and render components based on the configuration.
Just pick which components you want to cache by adding a cache
prop. As shown in readme;
export default class App extends Component {
render() {
return (
<div>
<ComponentNotToBeCached />
<ComponentToCache cache />
</div>
);
}
}
Does it work with nested components ?
I don't think it works for nested component ? Only the first level components ?