frontend-collective / react-sortable-tree

Drag-and-drop sortable component for nested data and hierarchies
https://frontend-collective.github.io/react-sortable-tree/
MIT License
4.9k stars 897 forks source link

How to setState in onDragStateChanged #915

Closed HughLK closed 2 years ago

HughLK commented 2 years ago

I want to show some tips at the top of SortableTree when drag is starting. So I called setState in onDragStateChanged . But it seems not work . How can I fix this?

const [dragState, setDragState] = useState(false);

<DragState draggingState={draggingState.current} />
<div>
    <SortableTree
        ...
        onDragStateChanged={({ isDragging, draggedNode }: OnDragStateChangedData) => {
               setDragState(isDragging);
         }}
    />
</div>

function DragState(props) {
    return props.draggingState ? (
        <div className="dragging-tip">
            <span>tips...</span>
        </div>) : null
}
HughLK commented 2 years ago

Currently, I use "setTimtout" to setState.