Connecting in HoF crashes plugin
davidjbradshaw opened this issue · comments
I have the following code
const createConnectedToolbarItem = (icon, onClick) => {
const mapStateToProps = { onClick }
connect(
null,
mapStateToProps,
)(createToolbarItem(icon))
}
export const DecrementCounter = createConnectedToolbarItem(REMOVE, dec)
export const IncrementCounter = createConnectedToolbarItem(PLUS, inc)
Which is causing the following error
TypeError: Cannot read property 'body' of undefined
at Object.getReturnNode (C:\Dev\sandbox-client\node_modules\eslint-plugin-react-redux\lib\utils.js:8:21)
at checkFunction (C:\Dev\sandbox-client\node_modules\eslint-plugin-react-redux\lib\rules\mapStateToProps-prefer-hoisted.js:34:28)
at VariableDeclaration.node.declarations.forEach (C:\Dev\sandbox-client\node_modules\eslint-plugin-react-redux\lib\rules\mapStateToProps-prefer-hoisted.js:46:11)
at Array.forEach (<anonymous>)
at VariableDeclaration (C:\Dev\sandbox-client\node_modules\eslint-plugin-react-redux\lib\rules\mapStateToProps-prefer-hoisted.js:43:25)
at listeners.(anonymous function).forEach.listener (C:\Dev\sandbox-client\node_modules\eslint\lib\util\safe-emitter.js:45:58)
at Array.forEach (<anonymous>)
at Object.emit (C:\Dev\sandbox-client\node_modules\eslint\lib\util\safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (C:\Dev\sandbox-client\node_modules\eslint\lib\util\node-event-generator.js:251:26)
at NodeEventGenerator.applySelectors (C:\Dev\sandbox-client\node_modules\eslint\lib\util\node-event-generator.js:280:22)
However, if I change that code as follows:
const createConnectedToolbarItem = (icon, onClick) =>
connect(
null,
{ onClick },
)(createToolbarItem(icon))
I get the correct error message
23:3 error Connect function argument #1 should be named mapDispatchToProps react-redux/connect-prefer-named-arguments
In the end I had to go with the following in order to get this to work
const createConnectedToolbarItem = (icon, onClick) =>
// eslint-disable-next-line react-redux/connect-prefer-named-arguments
connect(
null,
{ onClick },
)(createToolbarItem(icon))
@davidjbradshaw thank you for creating an issue and helping to improve this plugin.
The fix for the issue is released with 3.0.1