Search code examples
javascriptreactjsreduxeslintcreate-react-app

ESLint, Create React App and Unused Vars error


I have an application that is using CRA and having added redux into the mix I am now suddenly getting un-used vars linting errors when importing things like dispatch from redux.

Any help on why these might be coming back as unused would be really appreciated!

Create React app, Redux, Eslint, unused var error


Solution

  • You don't need the second line:

    import { dispatch } from 'redux'
    

    dispatch is added when you connect a component with redux automatically.

    The second import seems unneeded as well. The function that is making use of it is receiving it as part of its parameters already. The default state should be used to initialize the reducer instead.