frontend-collective/react-sortable-tree

How to setState in onDragStateChanged

HughLK opened this issue · 1 comments

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
}

Currently, I use "setTimtout" to setState.