I am working on a Drag and Drop scenario with react-beautiful-dnd, trying to add a drop animation, following the manual https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/guides/drop-animation.md.
Using typescript I am getting in trouble when I add a isDragging
property to a simple div element. Trying to work around this problem I was building a component with extended properties, following
Specify specific props and accept general HTML props in Typescript React App
This worked to some point, but is failing on the ref property.
My code:
interface IdragDiv extends React.HTMLAttributes<HTMLDivElement>, React.RefAttributes<HTMLDivElement> {
isDragging: boolean;
}
export class DragDiv extends React.Component<IdragDiv> {
render() {
const { children, ...rest } = this.props;
return <div {...rest}>{children}</div>;
}
}
Calling it like this:
...
return (
<Draggable
draggableId={...}
>
{(provided, snapshot) => {
return (
<DragDiv
{...className}
ref={provided.innerRef}
{...provided!.draggableProps}
{...provided!.dragHandleProps}
isDragging={snapshot.isDragging && !snapshot.isDropAnimating}
>
...
</DragDiv>
);
}}
</Draggable>
);
...
This results in following error:
(property) ref?: (string & ((instance: HTMLDivElement | null) => void)) | (string & React.RefObject<HTMLDivElement>) | (((instance: DragDiv | null) => void) & ((instance: HTMLDivElement | null) => void)) | ... 4 more ... | undefined
No overload matches this call.
Overload 1 of 2, '(props: Readonly<IdragDiv>): DragDiv', gave the following error.
Type '(element?: HTMLElement | null | undefined) => any' is not assignable to type '(string & ((instance: HTMLDivElement | null) => void)) | (string & RefObject<HTMLDivElement>) | (((instance: DragDiv | null) => void) & ((instance: HTMLDivElement | null) => void)) | ... 4 more ... | undefined'.
Type '(element?: HTMLElement | null | undefined) => any' is not assignable to type 'string & ((instance: HTMLDivElement | null) => void)'.
Type '(element?: HTMLElement | null | undefined) => any' is not assignable to type 'string'.
Overload 2 of 2, '(props: IdragDiv, context?: any): DragDiv', gave the following error.
Type '(element?: HTMLElement | null | undefined) => any' is not assignable to type '(string & ((instance: HTMLDivElement | null) => void)) | (string & RefObject<HTMLDivElement>) | (((instance: DragDiv | null) => void) & ((instance: HTMLDivElement | null) => void)) | ... 4 more ... | undefined'.
Type '(element?: HTMLElement | null | undefined) => any' is not assignable to type 'string & ((instance: HTMLDivElement | null) => void)'.
Type '(element?: HTMLElement | null | undefined) => any' is not assignable to type 'string'.
Any ideas, is there another way to solve this problem?