MCPcopy
hub / github.com/livebud/bud / createView

Function createView

framework/view/ssr/jsx.ts:12–35  ·  view source on GitHub ↗
(view: View)

Source from the content-addressed store, hash-verified

10}
11
12export function createView(view: View) {
13 return function ({ props, context }) {
14 let component = React.createElement(view.page, props, [])
15 for (let frame of view.frames) {
16 component = React.createElement(frame, props, component)
17 }
18 let component2 = React.createElement("div", { id: "bud_target" }, component)
19 const layout = view.layout || defaultLayout
20 let component3 = React.createElement(layout, props, component2)
21 let html = ReactSSR.renderToString(component3)
22 let inject = ""
23 const hydrate = JSON.stringify(props)
24 inject += `<script id="bud_props" type="text/template" defer>${hydrate}</script>`
25 inject += `<script type="module" src="${view.client}" defer></script>`
26 html = html.replace("</head>", inject + `</head>`)
27 return {
28 status: 200,
29 headers: {
30 "Content-Type": "text/html",
31 },
32 body: html,
33 }
34 }
35}
36
37function defaultLayout(props) {
38 return React.createElement(

Callers

nothing calls this directly

Calls 2

stringifyMethod · 0.80
replaceMethod · 0.80

Tested by

no test coverage detected