-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
render.js
35 lines (29 loc) · 881 Bytes
/
render.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable-next-line no-unused-vars */
import { h, render } from 'preact';
import { document } from 'global';
import { stripIndents } from 'common-tags';
let renderedStory;
const rootElement = document ? document.getElementById('root') : null;
export default function renderMain({
storyFn,
selectedKind,
selectedStory,
showMain,
showError,
// forceRender,
}) {
const element = storyFn();
if (!element) {
showError({
title: `Expecting a Preact element from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Did you forget to return the Preact element from the story?
Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
`,
});
return;
}
render(null, rootElement, renderedStory);
showMain();
renderedStory = render(element, rootElement);
}