Skip to content

Commit

Permalink
Fix use-render
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiasWorker committed Mar 9, 2024
1 parent 3bd17c9 commit 19be0c1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
15 changes: 0 additions & 15 deletions packages/use-child-nodes/test/use-render.test.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/use-render/example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { useRender } from "../src";
const MyComponent = c(
({ name, checked }) => {
useRender(<input type="checkbox" name={name} checked={checked} />);
useRender(() => (
<input type="checkbox" name={name} checked={checked} />
));

return (
<host shadowDom>
Expand Down
8 changes: 6 additions & 2 deletions packages/use-render/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ const fillHost = (vnode?: any) =>
* Generate a second render, this render escapes the current
* one and is useful for collaborative work between LightDOM and shadowDOM
*/
export function useRender(callback: () => any, args?: any[]) {
export function useRender(view: any, args?: any[]) {
const host = useHost();

host.id = host.id || Symbol();

useInsertionEffect(() => {
render(fillHost(callback), host.current, host.id);
render(
fillHost(typeof view === "function" ? view() : view),
host.current,
host.id,
);
}, args);
}
1 change: 0 additions & 1 deletion packages/use-render/test/example.tsx

This file was deleted.

2 changes: 2 additions & 0 deletions packages/use-render/test/use-render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ it("use-render", () => {
useRender(() => html`<button />`);
});

hooks.cleanEffects()()();

expect(container.querySelector("button")).to.not.equal(null);
});

0 comments on commit 19be0c1

Please sign in to comment.