@@ -26,7 +26,7 @@ function styled(tag: React.ComponentType<*> | string) {
26
26
}
27
27
}
28
28
29
- const Result = React . forwardRef ( ( props , ref ) => {
29
+ const render = ( props , ref ) => {
30
30
const { as : component = tag , class : className , ...rest } = props ;
31
31
32
32
let filteredProps ;
@@ -70,20 +70,23 @@ function styled(tag: React.ComponentType<*> | string) {
70
70
if ( tag . __linaria && tag !== component ) {
71
71
// If the underlying tag is a styled component, forward the `as` prop
72
72
// Otherwise the styles from the underlying component will be ignored
73
- return React . createElement (
74
- tag ,
75
- Object . assign ( filteredProps , {
76
- as : component ,
77
- } )
78
- ) ;
73
+ filteredProps . as = component ;
74
+
75
+ return React . createElement ( tag , filteredProps ) ;
79
76
}
80
77
81
78
return React . createElement ( component , filteredProps ) ;
82
- } ) ;
79
+ } ;
80
+
81
+ const Result = React . forwardRef
82
+ ? React . forwardRef ( render )
83
+ : // React.forwardRef won't available on older React versions and in Preact
84
+ // Fallback to a innerRef prop in that case
85
+ ( { innerRef, ...rest } ) => render ( rest , innerRef ) ;
83
86
84
87
Result . displayName = options . name ;
85
88
86
- // This properties will be read by the babel plugin for interpolation
89
+ // These properties will be read by the babel plugin for interpolation
87
90
/* $FlowFixMe */
88
91
Result . __linaria = {
89
92
className : options . class ,
0 commit comments