feat(keyhandler): add onNodeRemove callback

This commit is contained in:
moklick
2019-07-24 16:44:26 +02:00
parent 7b32ee660c
commit 4be80dd985
8 changed files with 166 additions and 43 deletions
+19
View File
@@ -0,0 +1,19 @@
import { useEffect, useContext } from 'react';
import { useKeyPress } from '../hooks';
import { setNodesSelection } from '../state/actions';
import { GraphContext } from '../GraphContext';
export default (props) => {
const { state, dispatch } = useContext(GraphContext);
const removePressed = useKeyPress('Backspace');
useEffect(() => {
if (removePressed && state.selectedNodeIds.length) {
props.onNodeRemove(state.selectedNodeIds);
dispatch(setNodesSelection({ isActive: false }));
}
}, [removePressed])
return null;
}