I am building a solution with react-dnd and discovered I was missing dependencies to the hooks.
const Component = (props) => {
const [, drop] = useDrop(() => ({
drop: () => {
dispatch(drop({ itemId: props.id }))
}
}), [props.id]); // <-- I was missing this!
...
}
For native react-hooks useEffect
, etc., there are eslint plugins detecting this, but I received no warnings for this.
Do such rules exist for react-dnd
No but you can extend the react-hooks/exhaustive-deps
to include react-dnd hooks
You can do
{
rules: {
// ...
"react-hooks/exhaustive-deps": ["error", {
additionalHooks: "(useDrag|useDrop)"
}]
}
}