Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: high order components #329

Merged
merged 2 commits into from
Mar 27, 2022
Merged

fix: high order components #329

merged 2 commits into from
Mar 27, 2022

Conversation

manucorporat
Copy link
Contributor

This works now:

utils.ts

import { $, component$, implicit$FirstArg, QRL, useHostElement } from '@builder.io/qwik';

export function factoryQrl<P>(componentQRL: QRL<(props: P) => any>) {
  return component$((props: P) => {
    return $(async () => {
      const hostElement = useHostElement();
      const Component = await componentQRL.resolve(hostElement);
      return (
        <div>
          <Component {...props} />
        </div>
      );
    });
  });
}
export const factory$ = implicit$FirstArg(factoryQrl);
import { $, component$, Host } from '@builder.io/qwik';
import { factory$ } from './utils';

export const A = factory$(() => {
  return <div>A</div>;
});

export const B = factory$(() => {
  return <div>B</div>;
});

export function Light(props: { prop: string }) {
  return <div>Light: {props.prop}</div>;
}

export const C = factory$(Light);

export const Factory = component$(() => {
  return $(() => {
    return (
      <Host>
        <A />
        <B />
        <C prop="wow!" />
      </Host>
    );
  });
});

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 26, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ab368a8
Status: ✅  Deploy successful!
Preview URL: https://b086da74.qwik-docs.pages.dev

View logs

@manucorporat manucorporat enabled auto-merge (squash) March 27, 2022 22:28
@manucorporat manucorporat merged commit f8e5f58 into main Mar 27, 2022
@manucorporat manucorporat deleted the high-order-cmp branch March 27, 2022 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant