Skip to content

Commit e3122cf

Browse files
committed
Remove React.forwardRef
1 parent 5c7f02b commit e3122cf

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

.changeset/twelve-gifts-do.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@emotion/primitives-core': major
3+
'@emotion/styled': major
4+
'@emotion/react': major
5+
---
6+
7+
Refs are no longer internally forwarded using `React.forwardRef`.

packages/primitives-core/src/styled.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function createStyled(
5050
}
5151

5252
// do we really want to use the same infra as the web since it only really uses theming?
53-
let Styled = React.forwardRef<unknown, StyledProps>((props, ref) => {
53+
let Styled: React.FC<StyledProps> = props => {
5454
const finalTag =
5555
(shouldUseAs && (props.as as React.ElementType)) || component
5656

@@ -78,12 +78,9 @@ export function createStyled(
7878
}
7979
}
8080
newProps.style = [css.apply(mergedProps, styles), props.style]
81-
if (ref) {
82-
newProps.ref = ref
83-
}
8481

8582
return React.createElement(finalTag, newProps)
86-
})
83+
}
8784

8885
Styled.displayName = `emotion(${getDisplayName(component)})`
8986

packages/react/src/context.tsx

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import { useContext, forwardRef } from 'react'
2+
import { useContext } from 'react'
33
import createCache, { EmotionCache } from '@emotion/cache'
44
import isDevelopment from '#is-development'
55
import isBrowser from '#is-browser'
@@ -27,23 +27,14 @@ export let __unsafe_useEmotionCache = function useEmotionCache() {
2727
return useContext(EmotionCacheContext)
2828
}
2929

30-
let withEmotionCache = function withEmotionCache<Props, RefType = any>(
31-
func: (
32-
props: React.PropsWithoutRef<Props>,
33-
context: EmotionCache,
34-
ref?: React.ForwardedRef<RefType>
35-
) => React.ReactNode
36-
):
37-
| React.FC<React.PropsWithoutRef<Props> & React.RefAttributes<RefType>>
38-
| React.ForwardRefExoticComponent<
39-
React.PropsWithoutRef<Props> & React.RefAttributes<RefType>
40-
> {
41-
return forwardRef<RefType, Props>((props, ref) => {
30+
let withEmotionCache = function withEmotionCache<Props>(
31+
func: (props: Props, context: EmotionCache) => React.ReactNode
32+
): React.FC<Props> {
33+
return props => {
4234
// the cache will never be null in the browser
4335
let cache = useContext(EmotionCacheContext)!
44-
45-
return func(props, cache, ref)
46-
})
36+
return func(props, cache)
37+
}
4738
}
4839

4940
if (!isBrowser) {

packages/react/src/theming.tsx

+5-8
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,16 @@ export function withTheme<
8585
C extends React.ComponentType<React.ComponentProps<C>>
8686
>(
8787
Component: C
88-
): React.ForwardRefExoticComponent<
88+
): React.FC<
8989
DistributiveOmit<React.ComponentProps<C>, 'theme'> & { theme?: Theme }
90-
>
91-
export function withTheme(
92-
Component: React.ComponentType<any>
93-
): React.ForwardRefExoticComponent<any> {
90+
> {
9491
const componentName = Component.displayName || Component.name || 'Component'
9592

96-
let WithTheme = React.forwardRef(function render(props, ref) {
93+
let WithTheme: React.FC<any> = function render(props) {
9794
let theme = React.useContext(ThemeContext)
9895

99-
return <Component theme={theme} ref={ref} {...props} />
100-
})
96+
return <Component theme={theme} {...props} />
97+
}
10198

10299
WithTheme.displayName = `WithTheme(${componentName})`
103100

0 commit comments

Comments
 (0)