Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 19 support: Migrate away from defaultProps #2580

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions src/view/droppable/connected-droppable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { Component } from 'react';
import { connect } from 'react-redux';
import memoizeOne from 'memoize-one';
import { invariant } from '../../invariant';
import type {
State,
DroppableId,
Expand All @@ -19,7 +18,6 @@ import type {
import type {
MapProps,
OwnProps,
DefaultProps,
Selector,
DispatchProps,
StateSnapshot,
Expand Down Expand Up @@ -227,26 +225,11 @@ const mapDispatchToProps: DispatchProps = {
updateViewportMaxScroll: updateViewportMaxScrollAction,
};

function getBody(): HTMLElement {
invariant(document.body, 'document.body is not ready');
return document.body;
}

const defaultProps = ({
mode: 'standard',
type: 'DEFAULT',
direction: 'vertical',
isDropDisabled: false,
isCombineEnabled: false,
ignoreContainerClipping: false,
renderClone: null,
getContainerForClone: getBody,
}: DefaultProps);

// Abstract class allows to specify props and defaults to component.
// All other ways give any or do not let add default props.
// eslint-disable-next-line
/*::
import { defaultProps } from './droppable';
class DroppableType extends Component<OwnProps> {
static defaultProps = defaultProps;
}
Expand Down Expand Up @@ -275,6 +258,4 @@ const ConnectedDroppable: typeof DroppableType = connect(
},
)(Droppable);

ConnectedDroppable.defaultProps = defaultProps;

export default ConnectedDroppable;
21 changes: 19 additions & 2 deletions src/view/droppable/droppable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useMemo, useCallback } from 'use-memo-one';
import React, { useRef, useContext, type Node } from 'react';
import { invariant } from '../../invariant';
import type { DraggableId } from '../../types';
import type { Props, Provided } from './droppable-types';
import type { DefaultProps, Props, Provided } from './droppable-types';
import useDroppablePublisher from '../use-droppable-publisher';
import Placeholder from '../placeholder';
import AppContext, { type AppContextValue } from '../context/app-context';
Expand All @@ -23,7 +23,24 @@ import AnimateInOut, {
} from '../animate-in-out/animate-in-out';
import { PrivateDraggable } from '../draggable/draggable-api';

export default function Droppable(props: Props) {
function getBody(): HTMLElement {
invariant(document.body, 'document.body is not ready');
return document.body;
}

export const defaultProps: DefaultProps = {
mode: 'standard',
type: 'DEFAULT',
direction: 'vertical',
isDropDisabled: false,
isCombineEnabled: false,
ignoreContainerClipping: false,
renderClone: null,
getContainerForClone: getBody,
};

export default function Droppable(passedProps: Props) {
const props = { ...defaultProps, ...passedProps };
const appContext: ?AppContextValue = useContext<?AppContextValue>(AppContext);
invariant(appContext, 'Could not find app context');
const { contextId, isMovementAllowed } = appContext;
Expand Down