Skip to content

Commit

Permalink
Add eslint-plugin-react-hooks.
Browse files Browse the repository at this point in the history
This also fixes a few warnings in DragGroup.js.
  • Loading branch information
jorendorff committed Oct 11, 2023
1 parent 150d9fa commit aa87ee2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"shared-node-browser": true,
"jest": true
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"css-loader": "^6.6.0",
"eslint": "^8.11.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.6.0",
"html-webpack-plugin": "^5.5.0",
"prettier": "^2.6.0",
"style-loader": "^3.3.1",
Expand Down
13 changes: 7 additions & 6 deletions src/components/DragGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@ export default function DragGroup({ dispatchGameState, gameState }) {
// Capture the pointer. If the pointer could not be captured successfully, end the drag.
const dragGroup = React.useRef(null);
React.useEffect(() => {
const element = dragGroup.current;
let ok = true;
try {
dragGroup.current.setPointerCapture(dragState.pointerID);
element.setPointerCapture(dragState.pointerID);
} catch (exc) {
console.warn("Failed to capture pointer:", exc);
ok = false;
}
ok &&= dragGroup.current.hasPointerCapture(dragState.pointerID);
ok &&= element.hasPointerCapture(dragState.pointerID);
if (!ok) {
dispatchGameState({ action: "dragEnd" });
}
// Cleanup function to release the pointer.
return () => {
if (ok && dragGroup.current) {
if (ok) {
try {
dragGroup.current.releasePointerCapture(dragState.pointerID);
element.releasePointerCapture(dragState.pointerID);
} catch (exc) {
// The pointer is invalid. Normal on touch screens. Ignore it.
}
}
};
}, [dragState.pointerID]);
}, [dragState.pointerID, dispatchGameState]);

// Multi-select timer.
React.useEffect(() => {
Expand All @@ -59,7 +60,7 @@ export default function DragGroup({ dispatchGameState, gameState }) {
clearTimeout(timerID);
}
};
}, [isShifting, dragState.destination.where, dragState.dragHasMoved]);
}, [isShifting, dragState.destination.where, dragState.dragHasMoved, dispatchGameState]);

// Compute location.
let top = dragState.pointer.y - dragState.pointerOffset.y;
Expand Down

0 comments on commit aa87ee2

Please sign in to comment.