Skip to content

Commit

Permalink
fix(qwik): use signal to track DOM ref
Browse files Browse the repository at this point in the history
  • Loading branch information
ianlet authored Oct 1, 2024
1 parent 0441bc9 commit 27f0010
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions content/2-templating/5-dom-ref/qwik/InputFocused.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { component$, useVisibleTask$, useRef } from "@builder.io/qwik";
import { component$, useVisibleTask$, useSignal } from "@builder.io/qwik";

export const InputFocused = component$(() => {
const inputElement = useRef(null);

useVisibleTask$(() => inputElement.current.focus());
const inputElement = useSignal<HTMLInputElement>();

useVisibleTask$(({ track }) => {
const el = track(inputElement);
el?.focus();
});

return <input type="text" ref={inputElement} />;
});

0 comments on commit 27f0010

Please sign in to comment.