Skip to content

Commit f865b5e

Browse files
authored
feat: pass ref when creating the component (#40)
1 parent ff54816 commit f865b5e

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

packages/react/src/runtime.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo, createElement } from 'react';
1+
import { useMemo, createElement, forwardRef, FC } from 'react';
22

33
export function $$styled(
44
Comp: any,
@@ -10,7 +10,7 @@ export function $$styled(
1010
};
1111
}
1212
) {
13-
function StyledComponent({ as, ...props }: any) {
13+
const StyledComponent: any = forwardRef(({ as, ...props }: any, ref) => {
1414
let CompToRender = as ?? Comp;
1515
const [variants, others] = useMemo(() => {
1616
const [classes, others]: any[] = [{}, {}];
@@ -31,11 +31,11 @@ export function $$styled(
3131
}, [variants, props.className]);
3232

3333
if (typeof CompToRender === 'string') {
34-
return createElement(CompToRender, { ...others, className });
34+
return createElement(CompToRender, { ...others, className, ref });
3535
}
3636

37-
return createElement(CompToRender, { ...props, className });
38-
}
37+
return createElement(CompToRender, { ...props, className, ref });
38+
});
3939

4040
StyledComponent.displayName = `Macaron(${Comp})`;
4141
StyledComponent.toString = () => StyledComponent.selector(null);

0 commit comments

Comments
 (0)