DianaSuvorova / eslint-plugin-react-redux

Enforcing best practices for react-redux

Home Page:https://www.npmjs.com/package/eslint-plugin-react-redux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rule proposal: All mapDispatchToProps / mapStateToProps entries should appear in propTypes

MrHen opened this issue · comments

commented

After doing some refactoring I ended up with the following:

const mapStateToProps = (state, props) => {
    return {
        foo: state.foo,
        bar: state.bar, // missing from propTypes
    };
};

const mapDispatchToProps = {
    loadFoo: fooAction,
    loadBar: barAction, // missing from propTypes
};

class Widget extends React.Component {
    static propTypes = {
        foo: PropTypes.string.isRequired,
        loadFoo: PropTypes.func.isRequired,
    };

    // ...
}

Both bar and loadBar are not in propTypes and they have been removed from Widget entirely. They are now completely extraneous and it would have been nice to see a lint message telling me to remove them.

The simplest way to do that seems to be to force them to appear in propTypes which would then cause a warning that they aren't used.

@MrHen , thanks for the suggestion. I like this proposal.