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

Add onError and onSuccess callbacks #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"test:coverage": "nwb test-react --coverage",
"test:watch": "nwb test-react --server",
"gh-pages": "gh-pages -d ./demo/dist",
"postinstall": "nwb build-react-component",
"prepublish": "npm run build",
"postpublish": "npm run gh-pages"
},
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ class MailchimpSubscribe extends React.Component {
status: "error",
message: err
});
if(this.props.onError!==undefined)this.props.onError();
} else if (data.result !== "success") {
this.setState({
status: "error",
message: data.msg
});
if(this.props.onError!==undefined)this.props.onError();
} else {
this.setState({
status: "success",
message: data.msg
});
if(this.props.onSuccess!==undefined) this.props.onSuccess();
}
}
)
Expand All @@ -57,7 +60,9 @@ class MailchimpSubscribe extends React.Component {

MailchimpSubscribe.propTypes = {
render: PropTypes.func,
url: PropTypes.string.isRequired
url: PropTypes.string.isRequired,
onSuccess: PropTypes.func,
onError: PropTypes.func,
Comment on lines +64 to +65

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are missing defaultProps below. For functions, it's a good practice to give a default value of a noop () => {} function.

Then, you won't need the if(this.props.onSuccess!==undefined) checks anymore.

};

MailchimpSubscribe.defaultProps = {
Expand Down