# Render

Returns HTML for a script tag with the possibility to pass data from the server. Framework agnostic.

Server data is embedded as JSON in script tags. <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#embedding_data_in_html>

## index.js

### render(\[props], \[settings]) ⇨ `String`

`@soleil-se/app-util/server`

Get a HTML string for rendering an application.

**Returns**: `String` - HTML for rendering an application.

| Param             | Type      | Default | Description                                                                                                                      |
| ----------------- | --------- | ------- | -------------------------------------------------------------------------------------------------------------------------------- |
| \[props]          | `Object`  | `{}`    | Props that will be passed to the app                                                                                             |
| \[settings]       | `Object`  | `{}`    | Settings object.                                                                                                                 |
| \[settings.html]  | `String`  | `”`     | HTML that will be rendered inside mount element.                                                                                 |
| \[settings.async] | `Boolean` | `false` | If the app script should be loaded asynchronously.                                                                               |
| \[settings.defer] | `Boolean` | `true`  | If the app script should be loaded after DOM is ready.                                                                           |
| \[settings.req]   | `Object`  |         | The req object from Sitevision, pass this to optimize browser specific script loading if you have multiple instances of the app. |

[Read more about async and defer.](https://flaviocopes.com/javascript-async-defer/)

### Example

```js
import router from '@Sitevision/api/common/router';
import { render } from '@soleil-se/app-util/server';


router.get('/', (req, res) => {
  const props = { foo: 'bar' };
  res.send(render(props));
};
```

**All settings**

```js
import router from '@Sitevision/api/common/router';
import { render } from '@soleil-se/app-util/server';


router.get('/', (req, res) => {
  const props = { foo: 'bar' };
  const settings = {
    html: '<noscript>You can put a noscript message here for example!</noscript>',
    async: false,
    defer: true,
    req,
  }
  res.send(render(props, settings));
};
```