Skip to content

Commit

Permalink
Merge branch 'dinkinflicka/optimize-rerenders-on-click' of https://gi…
Browse files Browse the repository at this point in the history
…thub.com/dinkinflickaa/dnd-kit into dinkinflicka/optimize-rerenders-on-click
  • Loading branch information
jain-sachin committed Oct 9, 2024
2 parents 8ea85a1 + cc865c6 commit 0923cc4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/components/DndContext/DndContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ export const DndContext = memo(function DndContext({
);

const activeSensorRef = useRef<SensorInstance | null>(null);
const activatorEventRef = useRef<Event | null>(null);
const instantiateSensor = useCallback(
(
event: React.SyntheticEvent,
Expand Down Expand Up @@ -388,7 +387,9 @@ export const DndContext = memo(function DndContext({
});

activeSensorRef.current = sensorInstance;
activatorEventRef.current = event.nativeEvent;

// Attach the sensor, this will call the onStart method if needed
sensorInstance.attach();

function createHandler(type: Action.DragEnd | Action.DragCancel) {
return async function handler() {
Expand Down Expand Up @@ -425,7 +426,6 @@ export const DndContext = memo(function DndContext({
setActiveSensor(null);
setActivatorEvent(null);
activeSensorRef.current = null;
activatorEventRef.current = null;

const eventName =
type === Action.DragEnd ? 'onDragEnd' : 'onDragCancel';
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/sensors/keyboard/KeyboardSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ export class KeyboardSensor implements SensorInstance {
this.handleKeyDown = this.handleKeyDown.bind(this);
this.handleCancel = this.handleCancel.bind(this);

this.attach();
}

private attach() {
public attach() {
this.handleStart();

this.windowListeners.add(EventName.Resize, this.handleCancel);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/sensors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ export interface SensorProps<T> {
onEnd(): void;
}

export type SensorInstance = {
export interface SensorInstance {
autoScrollEnabled: boolean;
attach(): void;
};

export type SensorActivatorFunction<T> = (
Expand Down

0 comments on commit 0923cc4

Please sign in to comment.