Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MrHen opened this issue May 20, 2019 · 1 comment

Comments

@MrHen
Copy link

MrHen commented May 20, 2019

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.

@DianaSuvorova
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants