You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-26Lines changed: 5 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,7 @@ const App = () => (
52
52
Primarily meant for use with prerendering via [`@preact/preset-vite`](https://github.com/preactjs/preset-vite#prerendering-configuration) or other prerendering systems that share the API. If you're server-side rendering your app via any other method, you can use `preact-render-to-string` (specifically `renderToStringAsync()`) directly.
A thin wrapper around Preact's `hydrate` export, it switches between hydrating and rendering the provided element, depending on whether the current page has been prerendered. Additionally, it checks to ensure it's running in a browser context before attempting any rendering, making it a no-op during SSR.
276
-
277
-
Pairs with the `prerender()` function.
278
-
279
-
Params:
280
-
281
-
-`jsx: ComponentChild` - The JSX element or component to render
282
-
-`parent?: Element | Document | ShadowRoot | DocumentFragment` - The parent element to render into. Defaults to `document.body` if not provided.
283
-
284
-
```js
285
-
import { hydrate } from'preact-iso';
286
-
287
-
constApp= () => (
288
-
<div class="app">
289
-
<h1>Hello World</h1>
290
-
</div>
291
-
);
292
-
293
-
hydrate(<App />);
294
-
```
295
-
296
-
However, it is just a simple utility method. By no means is it essential to use, you can always use Preact's `hydrate` export directly.
297
-
298
277
### `prerender`
299
278
300
279
Renders a Virtual DOM tree to an HTML string using `preact-render-to-string`. The Promise returned from `prerender()` resolves to an Object with `html` and `links[]` properties. The `html` property contains your pre-rendered static HTML markup, and `links` is an Array of any non-external URL strings found in links on the generated page.
0 commit comments