riot / ssr

Riot.js node Server Side Rendering
MIT License
32 stars 8 forks source link

How to render with nested components? #2

Closed damusix closed 5 years ago

damusix commented 5 years ago

I am trying to render nested components server side, for example:

<myLayout>
    <head is="meta"></head>
    <body>
        { content }
    </body>
</myLayout>

The following:

const Render = require('@riotjs/ssr').default;
const Register = require('@riotjs/ssr/register');

Register();

const name = 'default';
const tmpl = require('./default.riot').default;
const context = { title: 'hello world' }

let content = Render(name, tmpl, context);

Renders this:

<default is="layout"><meta></default>
GianlucaGuarini commented 5 years ago

And voilà https://codesandbox.io/s/riotjs-4-simple-ssr-h6lyo

paullaffitte commented 4 years ago

What if the child component have to be rendered asynchronously?