stencil-state-tunnel icon indicating copy to clipboard operation
stencil-state-tunnel copied to clipboard

vNode passed as children has unexpected type. Make sure it's using the correct h() function.

Open philipfeldmann opened this issue 6 years ago • 1 comments

When using state tunnel with stencil 1.3.3 I get vNode passed as children has unexpected type. Make sure it's using the correct h() function. I simply just followed the guide.

This is my tunnel:

import { h } from "@stencil/core";
import { createProviderConsumer } from "@stencil/state-tunnel";

export interface CollapsibleState {
  isOpen: boolean;
  setIsOpen: (fn: (oldVal: boolean) => boolean) => void;
}

export const CollapsibleTunnel = createProviderConsumer<CollapsibleState>(
  {
    isOpen: true,
    setIsOpen: () => false
  },
  (subscribe, child) => (
    <context-provider subscribe={subscribe} renderer={child}></context-provider>
  )
);

Setting up the provider:

export class Collapsible {
  @State()
  isOpen = false;

  render() {
    return (
      <div class="cui-collapsible">
        <CollapsibleTunnel.Provider
          state={{
            isOpen: this.isOpen,
            setIsOpen: fn => {
              this.isOpen = fn(this.isOpen);
            }
          }}
        >
          <slot />
        </CollapsibleTunnel.Provider>
      </div>
    );
  }
}

Using the tunnel:

export class CollapsibleBody {
  render() {
    return (
      <CollapsibleTunnel.Consumer>
        {({ setIsOpen }) => (
          <button onClick={() => setIsOpen(o => !o)}>Toggle</button>
        )}
      </CollapsibleTunnel.Consumer>
    );
  }
}

Types are also not correctly inferred to the Consumer, setIsOpen is typed as any.

philipfeldmann avatar Nov 27 '19 08:11 philipfeldmann

The warning message is coming from stencil core. See https://github.com/ionic-team/stencil/issues/2007

petermikitsh avatar Nov 27 '19 16:11 petermikitsh