Skip to content

Commit ee0e0cc

Browse files
authored
Merge pull request #5 from itsjavi/issue-3-react19
refactor: add React 19 compatibility
2 parents 20c6aa7 + a721f88 commit ee0e0cc

File tree

7 files changed

+938
-1004
lines changed

7 files changed

+938
-1004
lines changed

examples/yarn.lock

Lines changed: 682 additions & 790 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
}
3636
},
3737
"scripts": {
38+
"dev": "yarn build && cd ./examples && yarn dev",
3839
"build": "yarn build:core && yarn build:react",
3940
"build:core": "cd ./core && yarn && yarn build",
4041
"build:react": "cd ./react && yarn && yarn build"
@@ -68,5 +69,6 @@
6869
"devDependencies": {
6970
"vite": "^5.2.7",
7071
"vite-plugin-dts": "^3.8.1"
71-
}
72+
},
73+
"packageManager": "yarn@1.22.22"
7274
}

react/src/useDraggable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ export function useDraggable(config: DraggableConfig) {
161161
);
162162

163163
const draggable = useCallback(
164-
(child: React.ReactElement) => {
164+
(child: React.ReactElement<React.ComponentPropsWithRef<any>>) => {
165165
if (!child) {
166166
return null;
167167
}
168168

169169
const current = refs.current;
170170

171-
// @ts-ignore
172-
current.originalRef = child.ref;
171+
// @ts-ignore React 16-19+ refs compatibility.
172+
current.originalRef = child.props?.ref ?? child.ref;
173173

174174
const clone = React.cloneElement(child, { ref: componentRef });
175175

react/src/useDroppable.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,19 @@ export function useDroppable(config: DroppableConfig) {
9494
}
9595
}, []);
9696

97-
const droppable = useCallback((child: React.ReactElement | null) => {
98-
if (!child) {
99-
return null;
100-
}
97+
const droppable = useCallback(
98+
(child: React.ReactElement<React.ComponentPropsWithRef<any>> | null) => {
99+
if (!child) {
100+
return null;
101+
}
101102

102-
// @ts-ignore
103-
originalRef.current = child.ref;
103+
// @ts-ignore React 16-19+ refs compatibility.
104+
originalRef.current = child.props?.ref ?? child.ref;
104105

105-
return React.cloneElement(child, { ref: dropComponentRef });
106-
}, []);
106+
return React.cloneElement(child, { ref: dropComponentRef });
107+
},
108+
[]
109+
);
107110

108111
return {
109112
droppable,

react/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"baseUrl": ".",
4+
"lib": ["ES2015", "DOM"],
45
"strict": true,
56
"moduleResolution": "node",
67
"sourceMap": true,

react/yarn.lock

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
# yarn lockfile v1
33

44

5-
"@types/prop-types@*":
6-
version "15.7.12"
7-
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.12.tgz#12bb1e2be27293c1406acb6af1c3f3a1481d98c6"
8-
integrity sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==
9-
105
"@types/react@>=16.8.0":
11-
version "18.3.3"
12-
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.3.tgz#9679020895318b0915d7a3ab004d92d33375c45f"
13-
integrity sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==
6+
version "19.1.2"
7+
resolved "https://registry.yarnpkg.com/@types/react/-/react-19.1.2.tgz#11df86f66f188f212c90ecb537327ec68bfd593f"
8+
integrity sha512-oxLPMytKchWGbnQM9O7D67uPa9paTNxO7jVoNMXgkkErULBPhPARCfkKL9ytcIJJRGjbsVwW4ugJzyFFvm/Tiw==
149
dependencies:
15-
"@types/prop-types" "*"
1610
csstype "^3.0.2"
1711

1812
csstype@^3.0.2:
@@ -22,5 +16,3 @@ csstype@^3.0.2:
2216

2317
"snapdrag/core@file:../core":
2418
version "1.0.0"
25-
"snapdrag/core@file:../core":
26-
version "1.0.0"

yarn.lock

Lines changed: 235 additions & 191 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)