import { h, VNode } from 'preact';
import { createAddonDecorator, Render } from '../../index';
import { ContextsPreviewAPI } from '../ContextsPreviewAPI';

/**
 * This is the framework specific bindings for Preact.
 * '@storybook/preact' expects the returning object from a decorator to be a 'Preact vNode'.
 */
export const renderPreact: Render<VNode> = (contextNodes, propsMap, getStoryVNode) => {
  const { getRendererFrom } = ContextsPreviewAPI();
  return getRendererFrom(h)(contextNodes, propsMap, getStoryVNode);
};

export const withContexts = createAddonDecorator(renderPreact);

import Preact from 'preact';
import { createAddonDecorator, Render } from '../../index';
import { ContextsPreviewAPI } from '../ContextsPreviewAPI';

/**
 * This is the framework specific bindings for Preact.
 * '@storybook/preact' expects the returning object from a decorator to be a 'Preact vNode'.
 */
export const renderPreact: Render<Preact.VNode> = (contextNodes, propsMap, getStoryVNode) => {
  const { getRendererFrom } = ContextsPreviewAPI();
  return getRendererFrom(Preact.h)(contextNodes, propsMap, getStoryVNode);
};

export const withContexts = createAddonDecorator(renderPreact);

--- 
+++ 
@@ -1,4 +1,4 @@
-import Preact from 'preact';
+import { h, VNode } from 'preact';
 import { createAddonDecorator, Render } from '../../index';
 import { ContextsPreviewAPI } from '../ContextsPreviewAPI';
 
@@ -6,9 +6,9 @@
  * This is the framework specific bindings for Preact.
  * '@storybook/preact' expects the returning object from a decorator to be a 'Preact vNode'.
  */
-export const renderPreact: Render<Preact.VNode> = (contextNodes, propsMap, getStoryVNode) => {
+export const renderPreact: Render<VNode> = (contextNodes, propsMap, getStoryVNode) => {
   const { getRendererFrom } = ContextsPreviewAPI();
-  return getRendererFrom(Preact.h)(contextNodes, propsMap, getStoryVNode);
+  return getRendererFrom(h)(contextNodes, propsMap, getStoryVNode);
 };
 
 export const withContexts = createAddonDecorator(renderPreact);
Fix 'cannot read property h of undefined'
