Skip to content

Commit 5f5d2e7

Browse files
authored
Define callback refs inline to work with latest versions of Next.js / React (#942)
Callback refs defined as class functions don't get invoked in Next.js 14.2+ – and therefore don't work – perhaps because of changes to the underlying React which is at or near version 19.
1 parent 5467c08 commit 5f5d2e7

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/index.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -568,17 +568,6 @@ export class Rnd extends React.PureComponent<Props, State> {
568568
};
569569
}
570570

571-
refDraggable = (c: Draggable) => {
572-
if (!c) return;
573-
this.draggable = c;
574-
};
575-
576-
refResizable = (c: Resizable | null) => {
577-
if (!c) return;
578-
this.resizable = c;
579-
this.resizableElement.current = c.resizable;
580-
};
581-
582571
render() {
583572
const {
584573
disableDragging,
@@ -634,7 +623,10 @@ export class Rnd extends React.PureComponent<Props, State> {
634623

635624
return (
636625
<Draggable
637-
ref={this.refDraggable}
626+
ref={(c: Draggable) => {
627+
if (!c) return;
628+
this.draggable = c;
629+
}}
638630
handle={dragHandleClassName ? `.${dragHandleClassName}` : undefined}
639631
defaultPosition={defaultValue}
640632
onMouseDown={onMouseDown}
@@ -656,7 +648,11 @@ export class Rnd extends React.PureComponent<Props, State> {
656648
>
657649
<Resizable
658650
{...resizableProps}
659-
ref={this.refResizable}
651+
ref={(c: Resizable | null) => {
652+
if (!c) return;
653+
this.resizable = c;
654+
this.resizableElement.current = c.resizable;
655+
}}
660656
defaultSize={defaultValue}
661657
size={this.props.size}
662658
enable={typeof enableResizing === "boolean" ? getEnableResizingByFlag(enableResizing) : enableResizing}

0 commit comments

Comments
 (0)