Skip to content

Commit 26e3e7b

Browse files
committed
fix(types): import JSX to support React 19 / fix animated.div type error (pmndrs#2358)
React 19 moved the JSX namespace from global scope to the React module. This updates type definitions to explicitly import the `JSX` type from 'react', resolving issues issues for consumers using React 19+. Note: Backwards-compatible with React 18.
1 parent 0c88ea4 commit 26e3e7b

File tree

8 files changed

+12
-6
lines changed

8 files changed

+12
-6
lines changed

packages/animated/src/withAnimated.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const withAnimated = (Component: any, host: HostConfig) => {
6666

6767
const observer = new PropsObserver(callback, deps)
6868

69-
const observerRef = useRef<PropsObserver>(null)
69+
const observerRef = useRef<PropsObserver | null>(null)
7070
useIsomorphicLayoutEffect(() => {
7171
observerRef.current = observer
7272

packages/core/src/hooks/useSpring.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function createUpdater(Component: React.ComponentType<{ args: [any, any?] }>) {
139139
}
140140
})
141141

142-
function renderWithContext(elem: JSX.Element) {
142+
function renderWithContext(elem: React.JSX.Element) {
143143
const wrapped = (
144144
<SpringContextProvider {...context}>{elem}</SpringContextProvider>
145145
)

packages/core/src/types/transition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReactNode } from 'react'
1+
import { ReactNode, JSX } from 'react'
22
import {
33
Lookup,
44
ObjectFromUnion,

packages/shared/src/hooks/useMemoOne.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function useMemoOne<T>(getResult: () => T, inputs?: any[]): T {
1414
})
1515
)
1616

17-
const committed = useRef<Cache<T>>(null)
17+
const committed = useRef<Cache<T> | null>(null)
1818
const prevCache = committed.current
1919

2020
let cache = prevCache

targets/three/src/animated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
2-
import { CSSProperties, ForwardRefExoticComponent, FC } from 'react'
2+
import { CSSProperties, ForwardRefExoticComponent, FC, JSX } from 'react'
33
import {
44
AssignableKeys,
55
ComponentPropsWithRef,

targets/three/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ addEffect(() => {
1919
})
2020

2121
const host = createHost(primitives, {
22-
applyAnimatedValues: applyProps,
22+
applyAnimatedValues: (instance, props) => {
23+
applyProps(instance, props)
24+
return
25+
},
2326
})
2427

2528
export const animated = host.animated as WithAnimated

targets/three/src/primitives.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as THREE from 'three'
22
import '@react-three/fiber'
3+
import { JSX } from 'react'
34

45
export type Primitives = keyof JSX.IntrinsicElements
56

targets/web/src/primitives.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { JSX } from 'react'
2+
13
export type Primitives = keyof JSX.IntrinsicElements
24
export const primitives: Primitives[] = [
35
'a',

0 commit comments

Comments
 (0)