Skip to content

Commit e121f8d

Browse files
committed
fix using refs and events
1 parent e350cd6 commit e121f8d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

apps/qwik-demo-app/src/routes/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { component$ } from '@builder.io/qwik';
1+
import { component$, useSignal } from '@builder.io/qwik';
22
import { providers, selectedProvider } from '../providers';
33
import { Image } from 'qwik-image';
44

55
export default component$(() => {
6+
const ref = useSignal<HTMLImageElement>();
7+
68
return (
79
<>
810
Selected Provider<h1>{selectedProvider}</h1>
911
<Image
12+
ref={ref}
13+
onLoad$={() => {
14+
console.log('loaded');
15+
}}
1016
width={400}
1117
height={400}
1218
style={{ border: '2px solid red' }}

packages/qwik-image/src/lib/image.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
QRL,
33
QwikIntrinsicElements,
4+
Signal,
45
component$,
56
createContextId,
67
useComputed$,
@@ -10,7 +11,7 @@ import {
1011

1112
export const DEFAULT_RESOLUTIONS = [3840, 1920, 1280, 960, 640];
1213

13-
type ImageAttributes = Omit<QwikIntrinsicElements['img'], 'ref'>;
14+
type ImageAttributes = QwikIntrinsicElements['img'];
1415

1516
/**
1617
* @alpha
@@ -220,7 +221,10 @@ export const Image = component$<ImageProps>((props) => {
220221
children: undefined,
221222
};
222223

223-
const style = useComputed$(() => ({ ...props.style, ...getStyles(props) }));
224+
const style = useComputed$(() => ({
225+
...props.style,
226+
...getStyles(props),
227+
}));
224228
const sizes = useComputed$(() => getSizes(props));
225229
const srcSet = useComputed$(() => {
226230
const { src, width, height, aspectRatio, layout } = props;

0 commit comments

Comments
 (0)